mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Add authentication via GitHub
This commit is contained in:
parent
8ba5608689
commit
f70a5275f0
3
.gitignore
vendored
3
.gitignore
vendored
@ -19,3 +19,6 @@
|
|||||||
/coverage
|
/coverage
|
||||||
# Ignore encrypted secrets key file.
|
# Ignore encrypted secrets key file.
|
||||||
config/secrets.yml.key
|
config/secrets.yml.key
|
||||||
|
|
||||||
|
# Ignore master key for decrypting credentials and more.
|
||||||
|
/config/master.key
|
||||||
|
|||||||
@ -11,4 +11,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||||||
def developer
|
def developer
|
||||||
sign_in_with "Developer"
|
sign_in_with "Developer"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def github
|
||||||
|
sign_in_with "GitHub"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@ -21,7 +21,11 @@
|
|||||||
</b></span>
|
</b></span>
|
||||||
<%= link_to(t('application.sign_out'), destroy_user_session_path, method: :delete) %>
|
<%= link_to(t('application.sign_out'), destroy_user_session_path, method: :delete) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
<% if Rails.env.development? %>
|
||||||
<%= link_to(t('application.sign_in'), user_developer_omniauth_authorize_path) %>
|
<%= 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 %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
1
config/credentials.yml.enc
Normal file
1
config/credentials.yml.enc
Normal 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==
|
||||||
@ -233,8 +233,15 @@ Devise.setup do |config|
|
|||||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||||
# up on your models and hooks.
|
# up on your models and hooks.
|
||||||
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
# 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
|
# ==> Warden configuration
|
||||||
# If you want to use other strategies, that are not supported by Devise, or
|
# 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.
|
# change the failure app, you can configure them inside the config.warden block.
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
aXUUhT76Uhw5fnfkwOwNP1EWppHhl8QB/N0VNzb0BNcZ+S2xsq9biPVY9OakzXj24If4KV9hYw5LJkN1xmQcwxQMJ2lqdow6fkdwFuHnjPMNZyzr7G3aaLylpamkBUaY7paUfRVjJAWJge0l2cv/fZcKuRS2B2CmjqjdTfcvxHb9R/UXM1Vv10Cp88dPKlQ11SYd3g0m6W87TZL+Hut6hweKuvA6DJlnGpNH/B+yaVYPzVfkpCN7mtNv7HEtkfATMzeoPmeW10EgwfljntfPZ33l5+eOJvOidrme1vDzVKO7Ag==--7sKcvkcMXbiQWQdA--aIz51lRbRz/t/xnkvY8WTQ==
|
|
||||||
19
test/integration/translator_flow_test.rb
Normal file
19
test/integration/translator_flow_test.rb
Normal 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
|
||||||
@ -20,3 +20,13 @@ class ActiveSupport::TestCase
|
|||||||
sign_in translator
|
sign_in translator
|
||||||
end
|
end
|
||||||
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
|
||||||
Loading…
Reference in New Issue
Block a user