Class: OmniAuth::Strategies::GranicusAdmin

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/granicus-admin.rb

Defined Under Namespace

Classes: NoAuthorizationCodeError

Constant Summary collapse

DEFAULT_SCOPE =
''

Instance Method Summary collapse

Instance Method Details

#access_token_optionsObject



82
83
84
# File 'lib/omniauth/strategies/granicus-admin.rb', line 82

def access_token_options
  options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
end

#authorize_paramsObject

You can pass host or scope params to the auth request, if you need to set them dynamically. You can also set these options in the OmniAuth config :authorize_params option.



92
93
94
95
96
97
98
# File 'lib/omniauth/strategies/granicus-admin.rb', line 92

def authorize_params
  super.tap do |params|
    %w[scope].each { |v| params[v.to_sym] = request.params[v] if request.params[v] }
    params[:scope] ||= DEFAULT_SCOPE
    params[:host] = options.host
  end
end

#build_access_tokenObject



66
67
68
69
70
# File 'lib/omniauth/strategies/granicus-admin.rb', line 66

def build_access_token
  with_authorization_code! { super }.tap do |token|
      token.options.merge!(access_token_options)
  end
end

#callback_phaseObject

Implement multi-tenancy support in the callback phase with a check to ensure we are still talking to the right domain to prevent hijacking of the oauth token process



76
77
78
79
80
# File 'lib/omniauth/strategies/granicus-admin.rb', line 76

def callback_phase
  options.client_options[:site] = "https://#{options.host}"
  
  super
end

#clientObject



52
53
54
55
56
# File 'lib/omniauth/strategies/granicus-admin.rb', line 52

def client
  options.client_options[:site] = "https://#{options.host}"

  super
end

#raw_infoObject



58
59
60
61
62
63
64
# File 'lib/omniauth/strategies/granicus-admin.rb', line 58

def raw_info
  @raw_info ||= access_token.get('/auth/identity/me').parsed
  @raw_info['name'] ||= @raw_info['username']
  @raw_info['email'] ||= "#{@raw_info['username']}@#{options.host}"

  @raw_info
end