Class: Keyrod::OIDCClient

Inherits:
Object
  • Object
show all
Defined in:
lib/keyrod/oidc_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOIDCClient

Returns a new instance of OIDCClient.



8
9
10
11
12
13
14
# File 'lib/keyrod/oidc_client.rb', line 8

def initialize
  @oidc_site = Keyrod::Settings[:'oidc-site']
  @refresh_token = Keyrod::Settings[:'refresh-token']
  @client_id = Keyrod::Settings[:'client-id']
  @client_secret = Keyrod::Settings[:'client-secret']
  @ssl = Keyrod::Settings[:ssl]
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



6
7
8
# File 'lib/keyrod/oidc_client.rb', line 6

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



6
7
8
# File 'lib/keyrod/oidc_client.rb', line 6

def client_secret
  @client_secret
end

#oidc_siteObject (readonly)

Returns the value of attribute oidc_site.



6
7
8
# File 'lib/keyrod/oidc_client.rb', line 6

def oidc_site
  @oidc_site
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



6
7
8
# File 'lib/keyrod/oidc_client.rb', line 6

def refresh_token
  @refresh_token
end

#sslObject (readonly)

Returns the value of attribute ssl.



6
7
8
# File 'lib/keyrod/oidc_client.rb', line 6

def ssl
  @ssl
end

Instance Method Details

#access_tokenObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/keyrod/oidc_client.rb', line 16

def access_token
  conn = Faraday.new(oidc_site, ssl: ssl, params: params)

  logger.debug "access_token: Sending request with params #{conn.params}"
  response = conn.post
  logger.debug "Received response with code #{response.status} and body #{response.body}"
  raise Keyrod::Errors::ResponseError, "Response from OIDC server was #{response.status}" unless response.success?

  JSON.parse(response.body, symbolize_names: true)[:access_token]
end