Class: OmniAuth::Strategies::MicrosoftGraph
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::MicrosoftGraph
- Defined in:
- lib/omniauth/strategies/microsoft_graph.rb
Constant Summary collapse
- BASE_SCOPE_URL =
'https://graph.microsoft.com/'- BASE_SCOPES =
%w[offline_access openid email profile].freeze
- DEFAULT_SCOPE =
'offline_access openid email profile User.Read'.freeze
- YAMMER_PROFILE_URL =
'https://www.yammer.com/api/v1/users/current.json'- MICROSOFT_GRAPH_PROFILE_URL =
'https://graph.microsoft.com/v1.0/me'
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #authorize_params ⇒ Object
- #callback_url ⇒ Object
- #custom_build_access_token ⇒ Object (also: #build_access_token)
- #determine_profile_endpoint(request) ⇒ Object
- #profile_endpoint ⇒ Object
- #raw_info ⇒ Object
Instance Method Details
#auth_hash ⇒ Object
49 50 51 52 53 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 49 def auth_hash super.tap do |ah| verify_email(ah, access_token) end end |
#authorize_params ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 55 def super.tap do |params| [:authorize_options].each do |k| params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s]) end params[:scope] = get_scope(params) params[:access_type] = 'offline' if params[:access_type].nil? session['omniauth.state'] = params[:state] if params[:state] end end |
#callback_url ⇒ Object
72 73 74 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 72 def callback_url [:callback_url] || full_host + script_name + callback_path end |
#custom_build_access_token ⇒ Object Also known as: build_access_token
76 77 78 79 80 81 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 76 def custom_build_access_token access_token = get_access_token(request) # Get the profile(microsoft graph / yammer) endpoint choice based on returned bearer token @profile_endpoint = determine_profile_endpoint(request) access_token end |
#determine_profile_endpoint(request) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 89 def determine_profile_endpoint(request) scope = request&.env&.dig('omniauth.params', 'scope') if scope&.include?('yammer') YAMMER_PROFILE_URL else MICROSOFT_GRAPH_PROFILE_URL end end |
#profile_endpoint ⇒ Object
85 86 87 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 85 def profile_endpoint @profile_endpoint ||= MICROSOFT_GRAPH_PROFILE_URL end |
#raw_info ⇒ Object
68 69 70 |
# File 'lib/omniauth/strategies/microsoft_graph.rb', line 68 def raw_info @raw_info ||= access_token.get(profile_endpoint).parsed end |