Class: OmniAuth::Strategies::Ldsconnect

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

Defined Under Namespace

Classes: NoAuthorizationCodeError

Constant Summary collapse

DEFAULT_SCOPE =
''

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



42
43
44
45
46
# File 'lib/omniauth-ldsconnect/strategies/ldsconnect.rb', line 42

def authorize_params
  super.tap do |params|
    params[:scope] ||= DEFAULT_SCOPE
  end
end

#build_access_tokenObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omniauth-ldsconnect/strategies/ldsconnect.rb', line 48

def build_access_token
  ssl_options = options.client_options[:ssl].to_hash.symbolize_keys rescue {}
  token_client = Faraday.new url: options.client_options[:site], ssl: ssl_options
  post_params = {
    grant_type: 'authorization_code',
    code: request.params['code'],
    redirect_uri: self.callback_url,
  }
  auth = "Basic #{Base64.encode64([options.client_id, options.client_secret].join(':')).gsub("\n", '')}"
  resp = token_client.post(options.client_options[:token_url], post_params, 'Authorization'=>auth)
  decoded = MultiJson.decode resp.body
  token = decoded["access_token"]
  self.access_token = ::OAuth2::AccessToken.from_hash client, decoded.merge(access_token_options)
end

#profile_infoObject



37
38
39
40
# File 'lib/omniauth-ldsconnect/strategies/ldsconnect.rb', line 37

def profile_info
  url = "#{options.client_options[:profile_url]}?access_token=#{access_token.token}"
  @profile_info ||= access_token.get(url).parsed || { }
end