Class: CandidApiClient::Auth::V2::V2Client
- Inherits:
-
Object
- Object
- CandidApiClient::Auth::V2::V2Client
- Defined in:
- lib/candidhealth/auth/v_2/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#get_token(client_id:, client_secret:, request_options: nil) ⇒ CandidApiClient::Auth::V2::Types::AuthGetTokenResponse
<Callout intent=“info”> Candid Health SDKs automatically handle authentication workflows after configuring them with the ‘client_id` and `client_secret`.
- #initialize(request_client:) ⇒ CandidApiClient::Auth::V2::V2Client constructor
Constructor Details
#initialize(request_client:) ⇒ CandidApiClient::Auth::V2::V2Client
16 17 18 |
# File 'lib/candidhealth/auth/v_2/client.rb', line 16 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ CandidApiClient::RequestClient (readonly)
12 13 14 |
# File 'lib/candidhealth/auth/v_2/client.rb', line 12 def request_client @request_client end |
Instance Method Details
#get_token(client_id:, client_secret:, request_options: nil) ⇒ CandidApiClient::Auth::V2::Types::AuthGetTokenResponse
<Callout intent=“info”>
Candid Health SDKs automatically handle authentication workflows after
configuring them with the `client_id` and
`client_secret`.
</Callout>
Candid Health utilizes the [OAuth 2.0 bearer token authentication
scheme](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) in our
auth flow. You obtain the bearer token for all
subsequent API requests via the `/auth/token` endpoint defined below, which
requires you to provide your `client_id` and `client_secret`. Your `client_id`
and `client_secret` can be
incandidhealth.com/hc/en-us/articles/23065219476244--Generating-Candid-API-Keys)
from the "Users & Credentials" tab by your org admin.
The bearer token is a signed [JWT](https://jwt.io/). The public key for the JWT
can be found [here](https://candidhealth.auth0.com/pem) for any verification
workflows.
The bearer token should be provided in the `Authorization` header for all
subsequent API calls.
<Callout intent="warning">
The bearer token expires 5 hours after it has been created. After it has
expired, the client will receive an "HTTP 401
Unauthorized" error, at which point the client should generate a new token. It
is important that tokens be reused between
requests; if the client attempts to generate a token too often, it will be
rate-limited and will receive an `HTTP 429 Too Many Requests` error.
</Callout>
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/candidhealth/auth/v_2/client.rb', line 54 def get_token(client_id:, client_secret:, request_options: nil) response = @request_client.conn.post do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .token unless &.token.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), client_id: client_id, client_secret: client_secret }.compact req.url "#{@request_client.get_url(environment: CandidApi, request_options: )}/api/auth/v2/token" end CandidApiClient::Auth::V2::Types::AuthGetTokenResponse.from_json(json_object: response.body) end |