Class: Infisical::Auth
- Inherits:
-
Object
- Object
- Infisical::Auth
- Defined in:
- lib/infisical/auth.rb
Overview
Authenticates the underlying HTTP client. Every other resource client shares that same HTTP client, so a successful login here authenticates the whole Client instance.
Constant Summary collapse
- UNIVERSAL_AUTH_LOGIN_PATH =
"api/v1/auth/universal-auth/login"
Instance Method Summary collapse
-
#access_token(token) ⇒ String
Authenticates with an access token obtained out-of-band, skipping the login request entirely.
-
#initialize(http_client) ⇒ Auth
constructor
A new instance of Auth.
-
#universal_auth_login(client_id:, client_secret:) ⇒ Models::MachineIdentityCredential
Logs in with Universal Auth (machine identity client id/secret) and authenticates this client with the resulting access token.
Constructor Details
#initialize(http_client) ⇒ Auth
Returns a new instance of Auth.
13 14 15 |
# File 'lib/infisical/auth.rb', line 13 def initialize(http_client) @http_client = http_client end |
Instance Method Details
#access_token(token) ⇒ String
Authenticates with an access token obtained out-of-band, skipping the login request entirely.
45 46 47 48 |
# File 'lib/infisical/auth.rb', line 45 def access_token(token) @http_client.access_token = token token end |
#universal_auth_login(client_id:, client_secret:) ⇒ Models::MachineIdentityCredential
Logs in with Universal Auth (machine identity client id/secret) and
authenticates this client with the resulting access token. The full
credential is returned so callers can track expires_in and re-login
(or renew) before the token lapses.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/infisical/auth.rb', line 27 def universal_auth_login(client_id:, client_secret:) # auth: false keeps any previously stored (possibly expired) bearer # token off the login request; the API breaks on stale tokens there. response = @http_client.post( UNIVERSAL_AUTH_LOGIN_PATH, body: { clientId: client_id, clientSecret: client_secret }, auth: false ) access_token(response["accessToken"]) Models::MachineIdentityCredential.from_api(response) end |