Class: Keycardai::OAuth::ClientCredentialsClient
- Inherits:
-
Object
- Object
- Keycardai::OAuth::ClientCredentialsClient
- Includes:
- TokenRequests
- Defined in:
- lib/keycardai/oauth/client_credentials_client.rb
Overview
OAuth 2.0 client_credentials grant (RFC 6749 §4.4): autonomous workload authentication. The client requests a token for itself, with no user in the loop, and authenticates with a shared secret (HTTP Basic) or a client assertion carried on the request.
The token endpoint is discovered from the issuer on first use and cached. Requests do not retry transparently.
Instance Method Summary collapse
-
#initialize(issuer:, credential: nil, client_id: nil, client_secret: nil, http_client: HTTP::NetHTTPClient.new, timeout: nil) ⇒ ClientCredentialsClient
constructor
A new instance of ClientCredentialsClient.
-
#request_token(scope: nil, resource: nil, client_assertion: nil, client_assertion_type: nil, issuer: nil) ⇒ TokenResponse
Request a token for the client itself.
Methods included from TokenRequests
Constructor Details
#initialize(issuer:, credential: nil, client_id: nil, client_secret: nil, http_client: HTTP::NetHTTPClient.new, timeout: nil) ⇒ ClientCredentialsClient
Returns a new instance of ClientCredentialsClient.
26 27 28 29 30 |
# File 'lib/keycardai/oauth/client_credentials_client.rb', line 26 def initialize(issuer:, credential: nil, client_id: nil, client_secret: nil, http_client: HTTP::NetHTTPClient.new, timeout: nil) initialize_token_client(issuer: issuer, credential: credential, client_id: client_id, client_secret: client_secret, http_client: http_client, timeout: timeout) end |
Instance Method Details
#request_token(scope: nil, resource: nil, client_assertion: nil, client_assertion_type: nil, issuer: nil) ⇒ TokenResponse
Request a token for the client itself.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/keycardai/oauth/client_credentials_client.rb', line 43 def request_token(scope: nil, resource: nil, client_assertion: nil, client_assertion_type: nil, issuer: nil) post_token_request( { "grant_type" => GrantType::CLIENT_CREDENTIALS, "scope" => scope, "resource" => resource, "client_assertion" => client_assertion, "client_assertion_type" => client_assertion_type }, issuer: issuer || @issuer ) end |