Class: Booqable::OAuthClient
- Inherits:
-
Object
- Object
- Booqable::OAuthClient
- Defined in:
- lib/booqable/oauth_client.rb
Overview
OAuth2 client for Booqable API authentication
Provides OAuth2 authentication flow support for the Booqable API. Handles authorization code exchange for access tokens using the standard OAuth2 authorization code flow.
Constant Summary collapse
- TOKEN_ENDPOINT =
OAuth2 token endpoint path
"/oauth/token"
Instance Method Summary collapse
-
#get_access_token_from_hash(hash) ⇒ OAuth2::AccessToken
Create an access token from a hash.
-
#get_token_from_code(code, scope: "full_access") ⇒ OAuth2::AccessToken
Exchange an authorization code for an access token.
-
#initialize(api_endpoint:, client_id:, client_secret:, redirect_uri: nil) ⇒ OAuthClient
constructor
Initialize a new OAuth client.
Constructor Details
#initialize(api_endpoint:, client_id:, client_secret:, redirect_uri: nil) ⇒ OAuthClient
Initialize a new OAuth client
33 34 35 36 37 38 39 40 41 |
# File 'lib/booqable/oauth_client.rb', line 33 def initialize(api_endpoint:, client_id:, client_secret:, redirect_uri: nil) @client = OAuth2::Client.new( client_id, client_secret, site: api_endpoint, token_url: api_endpoint + TOKEN_ENDPOINT, ) @redirect_uri = redirect_uri end |
Instance Method Details
#get_access_token_from_hash(hash) ⇒ OAuth2::AccessToken
Create an access token from a hash.
68 69 70 |
# File 'lib/booqable/oauth_client.rb', line 68 def get_access_token_from_hash(hash) OAuth2::AccessToken.from_hash(@client, hash) end |
#get_token_from_code(code, scope: "full_access") ⇒ OAuth2::AccessToken
Exchange an authorization code for an access token
Exchanges the authorization code received from the OAuth callback for an access token that can be used to make API requests.
57 58 59 60 61 62 |
# File 'lib/booqable/oauth_client.rb', line 57 def get_token_from_code(code, scope: "full_access") @client.auth_code.get_token(code, redirect_uri: @redirect_uri, scope: scope, grant_type: "authorization_code") end |