Class: OmniAuth::Strategies::AtlassianOauth2
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::AtlassianOauth2
- Defined in:
- lib/omniauth/strategies/atlassian_oauth2.rb
Overview
Omniauth strategy for Atlassian
Instance Method Summary collapse
Instance Method Details
#raw_info ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/omniauth/strategies/atlassian_oauth2.rb', line 46 def raw_info return @raw_info if @raw_info # NOTE: api.atlassian.com, not auth.atlassian.com! accessible_resources_url = 'https://api.atlassian.com/oauth/token/accessible-resources' sites = JSON.parse(access_token.get(accessible_resources_url).body) # Jira's OAuth gives us many potential sites. To request information # about the user for the OmniAuth hash, pick the first one that has the # necessary 'read:jira-user' scope. jira_user_scope = 'read:jira-user' site = sites.find do |candidate_site| candidate_site['scopes'].include?(jira_user_scope) end unless site raise "No site found with scope #{jira_user_scope}, please ensure the scope ${jira_user_scope} is added to your OmniAuth config" end cloud_id = site['id'] base_url = "https://api.atlassian.com/ex/jira/#{cloud_id}" myself_url = "#{base_url}/rest/api/3/myself" myself = JSON.parse(access_token.get(myself_url).body) @raw_info ||= { 'site' => site, 'sites' => sites, 'myself' => myself } end |