Class: Candid::Auth::Default::Client
- Inherits:
-
Object
- Object
- Candid::Auth::Default::Client
- Defined in:
- lib/candid/auth/default/client.rb
Instance Method Summary collapse
-
#get_token(request_options: {}, **params) ⇒ Candid::Auth::Default::Types::AuthGetTokenResponse
Candid Health SDKs automatically handle authentication workflows after configuring them with the client_idandclient_secret. - #initialize(client:, base_url: nil, environment: nil) ⇒ void constructor
Constructor Details
#initialize(client:, base_url: nil, environment: nil) ⇒ void
12 13 14 15 16 |
# File 'lib/candid/auth/default/client.rb', line 12 def initialize(client:, base_url: nil, environment: nil) @client = client @base_url = base_url @environment = environment end |
Instance Method Details
#get_token(request_options: {}, **params) ⇒ Candid::Auth::Default::Types::AuthGetTokenResponse
Candid Health utilizes the OAuth 2.0 bearer token authentication
scheme in our auth flow. You obtain the
bearer token for all
subsequent API requests via the /auth/v2/token endpoint defined below, which requires you to provide your
client_id and client_secret. Your client_id and client_secret can be
generated
from the "Users & Credentials" tab by your org admin.
The /auth/v2/token endpoint accepts both Content-Type: application/json and Content-Type: application/x-www-form-urlencoded. The request body should contain the client_id and client_secret as
follows:
{
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
}
or as URL-encoded form data:
client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET
The bearer token is a signed JWT. The public key for the JWT can be found here for any verification workflows.
The bearer token should be provided in the Authorization header for all subsequent API calls.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/candid/auth/default/client.rb', line 71 def get_token(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "POST", path: "/api/auth/v2/token", body: Candid::Auth::Default::Types::AuthGetTokenRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::Auth::Default::Types::AuthGetTokenResponse.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |