1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2025-12-10 00:36:42 +01:00

Add authentication via GitHub

This commit is contained in:
Philipp Fischbeck 2019-02-04 16:06:09 +01:00
parent 8ba5608689
commit f70a5275f0
8 changed files with 50 additions and 3 deletions

3
.gitignore vendored
View File

@ -19,3 +19,6 @@
/coverage
# Ignore encrypted secrets key file.
config/secrets.yml.key
# Ignore master key for decrypting credentials and more.
/config/master.key

View File

@ -11,4 +11,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def developer
sign_in_with "Developer"
end
def github
sign_in_with "GitHub"
end
end

View File

@ -21,7 +21,11 @@
</b></span>
<%= link_to(t('application.sign_out'), destroy_user_session_path, method: :delete) %>
<% else %>
<% if Rails.env.development? %>
<%= link_to(t('application.sign_in'), user_developer_omniauth_authorize_path) %>
<% else %>
<%= link_to(t('application.sign_in'), user_github_omniauth_authorize_path) %>
<% end %>
<% end %>
<% end %>
<% end %>

View File

@ -0,0 +1 @@
fmujPxH4j3Pge1kfEi/+pTVW7yA6/X3pBWwuLTIRhchpJokcEie/lbUNlpGOhzGUeOaNZpdEWbB+DVh7r8VUf9FaTMZwyA8u7ipB6Kt7FxrmyqGF4Sb3N54JdREq5KetMCR209VR5URghVnTv6fWMNY/CnfmoAhIi6z40ARP//wSgSQIYlTSsIF/LWdaI9Zn6v3eJ4KSs53EeHyIUal5E67QnvPESwWLvZ6BrKh6GO67xfjAKnoWU4YK+bkFeffubRSKqbb9fAHZLiEVD0glOAeibuJzLAZZa5worvQQgJLZnS1syWCDIz4U6PN4/ZBfrxq8Y+TpBXCEu/5JWrr6ARqbQy8Qnte+IL5EYY65Z70vyI9fcpVYiyKtvUQOsOypf/UxMjahg0MSddZlAiY3+ufyA1Sw9s7BCClaaNtOCtRM/thwNRdn3kNh2S/9YuodVSu5PV/V6DDX9BSo/FZeTbntBSsFnIe5NWwyEaC7jn1zp0FXeAT1N7beUpYcIwWXl7roGATq5J+eSycSAydj5TSPpy6pe0JV--zgHjFhqIX9PMSptP--a4kSt219OHlMrnkVTQFQVA==

View File

@ -233,8 +233,15 @@ Devise.setup do |config|
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
config.omniauth :developer, fields: [:name], uid_field: :name
if Rails.env.development?
config.omniauth :developer, fields: [:name], uid_field: :name
end
if Rails.env.production?
config.omniauth :github, Rails.application.credentials.github[:client_id], Rails.application.credentials.github[:client_secret], scope: ''
end
if Rails.env.test?
config.omniauth :github, '', '', scope: ''
end
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block.

View File

@ -1 +0,0 @@
aXUUhT76Uhw5fnfkwOwNP1EWppHhl8QB/N0VNzb0BNcZ+S2xsq9biPVY9OakzXj24If4KV9hYw5LJkN1xmQcwxQMJ2lqdow6fkdwFuHnjPMNZyzr7G3aaLylpamkBUaY7paUfRVjJAWJge0l2cv/fZcKuRS2B2CmjqjdTfcvxHb9R/UXM1Vv10Cp88dPKlQ11SYd3g0m6W87TZL+Hut6hweKuvA6DJlnGpNH/B+yaVYPzVfkpCN7mtNv7HEtkfATMzeoPmeW10EgwfljntfPZ33l5+eOJvOidrme1vDzVKO7Ag==--7sKcvkcMXbiQWQdA--aIz51lRbRz/t/xnkvY8WTQ==

View File

@ -0,0 +1,19 @@
require 'test_helper'
class TranslatorFlowTest < ActionDispatch::IntegrationTest
test "can view a problem" do
get '/problems/1'
assert_response :success
assert_select "h1", "First title Problem 1"
end
test "can login via github" do
get '/users/auth/github'
assert_response :redirect
follow_redirect!
follow_redirect!
assert_response :success
assert controller.user_signed_in?
assert_equal "translator", controller.current_user.name
end
end

View File

@ -20,3 +20,13 @@ class ActiveSupport::TestCase
sign_in translator
end
end
class ActionDispatch::IntegrationTest
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new({
provider: :github,
uid: 'translator',
name: 'translator'
})
end