Class: TRMNLP::OAuth::Client
- Inherits:
-
Object
- Object
- TRMNLP::OAuth::Client
- Defined in:
- lib/trmnlp/oauth/client.rb
Instance Method Summary collapse
- #authorize_url(redirect_uri:, state:, code_challenge: nil) ⇒ Object
- #exchange_code(code:, redirect_uri:, code_verifier: nil) ⇒ Object
-
#initialize(provider) ⇒ Client
constructor
A new instance of Client.
- #refresh(refresh_token:) ⇒ Object
Constructor Details
#initialize(provider) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/trmnlp/oauth/client.rb', line 9 def initialize(provider) @provider = provider end |
Instance Method Details
#authorize_url(redirect_uri:, state:, code_challenge: nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/trmnlp/oauth/client.rb', line 13 def (redirect_uri:, state:, code_challenge: nil) params = { redirect_uri:, scope: provider.scopes, state: } params.merge!(code_challenge:, code_challenge_method: 'S256') if code_challenge oauth_client(provider.token_url).auth_code.(**params) end |
#exchange_code(code:, redirect_uri:, code_verifier: nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/trmnlp/oauth/client.rb', line 19 def exchange_code(code:, redirect_uri:, code_verifier: nil) params = { redirect_uri: } params[:code_verifier] = code_verifier if code_verifier bundle oauth_client(provider.token_url).auth_code.get_token(code, params) end |
#refresh(refresh_token:) ⇒ Object
25 26 27 28 |
# File 'lib/trmnlp/oauth/client.rb', line 25 def refresh(refresh_token:) client = oauth_client(provider.refresh_url) bundle OAuth2::AccessToken.new(client, nil, refresh_token:).refresh! end |