Class: EdFi::Client::Auth
- Inherits:
-
Object
- Object
- EdFi::Client::Auth
- 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
-
#initialize(client:, client_id:, client_secret:) ⇒ Auth
constructor
A new instance of Auth.
-
#token ⇒ String
Gives an access token string that is guaranteed to be valid for at least 5 seconds.
Constructor Details
#initialize(client:, client_id:, client_secret:) ⇒ Auth
Returns a new instance of Auth
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
#token ⇒ String
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.
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 |