Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users of a specific GitHub organization to login #642

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ def github
github_token = env["omniauth.auth"].credentials.token
github_user = User.where(:github_login => github_login).first

if github_user.nil? && Errbit::Config.github_org_id
# See if they are a member of the organization that we have access for
# If they are, automatically create an account
client = client = Octokit::Client.new :access_token => github_token
org_ids = client.organizations.map { |org| org.id.to_s }
if org_ids.include? Errbit::Config.github_org_id
github_user = User.create(name: env["omniauth.auth"].extra.raw_info.name, email: env["omniauth.auth"].extra.raw_info.email)
end
end

# If user is already signed in, link github details to their account
if current_user
# ... unless a user is already registered with same github login
Expand Down
1 change: 1 addition & 0 deletions config/initializers/_load_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Errbit::Config.github_authentication = ENV['GITHUB_AUTHENTICATION']
Errbit::Config.github_client_id = ENV['GITHUB_CLIENT_ID']
Errbit::Config.github_secret = ENV['GITHUB_SECRET']
Errbit::Config.github_org_id = ENV['GITHUB_ORG_ID'] if ENV['GITHUB_ORG_ID']
Errbit::Config.github_access_scope = ENV['GITHUB_ACCESS_SCOPE'].split(',').map(&:strip) if ENV['GITHUB_ACCESS_SCOPE']

Errbit::Config.smtp_settings = {
Expand Down