Class: OmniAuth::Strategies::MicrosoftBusinessCentral

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/microsoft_business_central.rb

Constant Summary collapse

SCOPE_PREFIX =

The Business Central API audience; bare scope names are qualified against it.

'https://api.businesscentral.dynamics.com/'
DEFAULT_SCOPE =
"#{SCOPE_PREFIX}user_impersonation offline_access"
OPENID_SCOPES =

OpenID Connect scopes that must be passed through unqualified.

%w[openid email profile offline_access].freeze

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/omniauth/strategies/microsoft_business_central.rb', line 59

def authorize_params
  super.tap do |params|
    # Any whitelisted authorize option can also be supplied per request:
    # /auth/microsoft_business_central?login_hint=user@example.com
    options[:authorize_options].each do |key|
      value = request.params[key.to_s]
      params[key] = value unless value.nil? || value == ''
    end

    params[:scope] = normalize_scope(params[:scope] || DEFAULT_SCOPE)
  end
end

#callback_urlObject

OmniAuth::Strategy#callback_url appends the callback request's own query string, and the Microsoft identity platform requires redirect_uri to match the registered value exactly. omniauth 2's callback_path already carries SCRIPT_NAME, so mount prefixes must not be added again.



76
77
78
# File 'lib/omniauth/strategies/microsoft_business_central.rb', line 76

def callback_url
  options[:callback_url] || (full_host + callback_path)
end

#clientObject



51
52
53
54
55
56
57
# File 'lib/omniauth/strategies/microsoft_business_central.rb', line 51

def client
  client_options = deep_symbolize(options.client_options)
  tenant = options.tenant_id || 'common'
  client_options[:authorize_url] ||= "#{tenant}/oauth2/v2.0/authorize"
  client_options[:token_url] ||= "#{tenant}/oauth2/v2.0/token"
  ::OAuth2::Client.new(options.client_id, options.client_secret, client_options)
end