gitlab-org--gitlab-foss/lib/omni_auth/strategies/bitbucket.rb
gfyoung c8755543f0 Enable even more frozen string in lib/**/*.rb
Enables frozen string for the following files:

* lib/generators/**/*.rb
* lib/gitaly/**/*.rb
* lib/google_api/**/*.rb
* lib/haml_lint/**/*.rb
* lib/json_web_token/**/*.rb
* lib/mattermost/**/*.rb
* lib/microsoft_teams/**/*.rb
* lib/object_storage/**/*.rb
* lib/omni_auth/**/*.rb
* lib/peek/**/*.rb
* lib/rouge/**/*.rb
* lib/rspec_flaky/**/*.rb
* lib/system_check/**/*.rb

Partially addresses #47424.
2018-10-08 11:16:49 -07:00

47 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'omniauth-oauth2'
module OmniAuth
module Strategies
class Bitbucket < OmniAuth::Strategies::OAuth2
option :name, 'bitbucket'
option :client_options, {
site: 'https://bitbucket.org',
authorize_url: 'https://bitbucket.org/site/oauth2/authorize',
token_url: 'https://bitbucket.org/site/oauth2/access_token'
}
uid do
raw_info['username']
end
info do
{
name: raw_info['display_name'],
avatar: raw_info['links']['avatar']['href'],
email: primary_email
}
end
def raw_info
@raw_info ||= access_token.get('api/2.0/user').parsed
end
def primary_email
primary = emails.find { |i| i['is_primary'] && i['is_confirmed'] }
primary && primary['email'] || nil
end
def emails
email_response = access_token.get('api/2.0/user/emails').parsed
@emails ||= email_response && email_response['values'] || nil
end
def callback_url
options[:redirect_uri] || (full_host + script_name + callback_path)
end
end
end
end