Class: EdFi::Client::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/ed_fi/client/auth.rb

Overview

The EdFi::Client::Auth represents a complete authentication mechanism that makes the necessary calls for authorization codes and access tokens, keeps track of any token generated, and re-requests new tokens as necessary based on the existing token's lifecycle.

Constant Summary collapse

AUTHORIZATION_CODE_URI =

The URI to request an authorization code.

'/oauth/authorize'.freeze
AUTHORIZATION_CODE_CONTENT_TYPE =

The MIME content type to use for authorization code requests.

'application/x-www-form-urlencoded'.freeze
ACCESS_TOKEN_URI =

The URI to request an access token.

'/oauth/token'.freeze
ACCESS_TOKEN_CONTENT_TYPE =

The MIME content type to use for access token requests.

'application/json'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client:, client_id:, client_secret:) ⇒ Auth

Returns a new instance of Auth

Parameters:

  • client (Crapi::Client)

    The client to use for making auth calls.

  • client_id (String)

    The client id to use for authentication. This is AKA the “api key” / “username”.

  • client_secret (String)

    The client secret to use for authentication. This is AKA the “api secret” / “password”.



37
38
39
40
41
42
43
# File 'lib/ed_fi/client/auth.rb', line 37

def initialize(client:, client_id:, client_secret:)
  @client = client
  @client_id = client_id
  @client_secret = client_secret

  @access_token = nil
end

Instance Method Details

#tokenString

Gives an access token string that is guaranteed to be valid for at least 5 seconds.

Note a new token is requested and returned if the existing token is no longer valid.

Returns:

  • (String)


52
53
54
55
# File 'lib/ed_fi/client/auth.rb', line 52

def token
  @access_token = new_access_token unless @access_token&.valid?
  @access_token.token
end