Commit e00e501e8e73dca44124a4ee692e58af70cb8242

Authored by pyro2927
1 parent e6d72ea1
Exists in master and in 1 other branch production

Allow users of a specific GitHub organization to login

app/controllers/users/omniauth_callbacks_controller.rb
@@ -4,6 +4,16 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController @@ -4,6 +4,16 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
4 github_token = env["omniauth.auth"].credentials.token 4 github_token = env["omniauth.auth"].credentials.token
5 github_user = User.where(:github_login => github_login).first 5 github_user = User.where(:github_login => github_login).first
6 6
  7 + if github_user.nil? && Errbit::Config.github_org_id
  8 + # See if they are a member of the organization that we have access for
  9 + # If they are, automatically create an account
  10 + client = client = Octokit::Client.new :access_token => github_token
  11 + org_ids = client.organizations.map { |org| org.id.to_s }
  12 + if org_ids.include? Errbit::Config.github_org_id
  13 + github_user = User.create(name: env["omniauth.auth"].extra.raw_info.name, email: env["omniauth.auth"].extra.raw_info.email)
  14 + end
  15 + end
  16 +
7 # If user is already signed in, link github details to their account 17 # If user is already signed in, link github details to their account
8 if current_user 18 if current_user
9 # ... unless a user is already registered with same github login 19 # ... unless a user is already registered with same github login
config/initializers/_load_config.rb
@@ -24,6 +24,7 @@ unless defined?(Errbit::Config) @@ -24,6 +24,7 @@ unless defined?(Errbit::Config)
24 Errbit::Config.github_authentication = ENV['GITHUB_AUTHENTICATION'] 24 Errbit::Config.github_authentication = ENV['GITHUB_AUTHENTICATION']
25 Errbit::Config.github_client_id = ENV['GITHUB_CLIENT_ID'] 25 Errbit::Config.github_client_id = ENV['GITHUB_CLIENT_ID']
26 Errbit::Config.github_secret = ENV['GITHUB_SECRET'] 26 Errbit::Config.github_secret = ENV['GITHUB_SECRET']
  27 + Errbit::Config.github_org_id = ENV['GITHUB_ORG_ID'] if ENV['GITHUB_ORG_ID']
27 Errbit::Config.github_access_scope = ENV['GITHUB_ACCESS_SCOPE'].split(',').map(&:strip) if ENV['GITHUB_ACCESS_SCOPE'] 28 Errbit::Config.github_access_scope = ENV['GITHUB_ACCESS_SCOPE'].split(',').map(&:strip) if ENV['GITHUB_ACCESS_SCOPE']
28 29
29 Errbit::Config.smtp_settings = { 30 Errbit::Config.smtp_settings = {