Class: Asana::Authentication::OAuth2::AccessTokenAuthentication
- Inherits:
-
Object
- Object
- Asana::Authentication::OAuth2::AccessTokenAuthentication
- Defined in:
- lib/asana/authentication/oauth2/access_token_authentication.rb
Overview
A mechanism to authenticate with an OAuth2 access token (a bearer token and a refresh token) or just a refresh token.
Class Method Summary collapse
-
.from_refresh_token(refresh_token, client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) ⇒ AccessTokenAuthentication
Builds an AccessTokenAuthentication from a refresh token and client credentials, by refreshing into a new one.
Instance Method Summary collapse
-
#configure(connection) ⇒ void
Configures a Faraday connection injecting a bearer token, auto-refreshing it when needed.
-
#initialize(access_token) ⇒ AccessTokenAuthentication
constructor
Initializes a new AccessTokenAuthentication.
Constructor Details
#initialize(access_token) ⇒ AccessTokenAuthentication
Initializes a new AccessTokenAuthentication.
34 35 36 |
# File 'lib/asana/authentication/oauth2/access_token_authentication.rb', line 34 def initialize(access_token) @token = access_token end |
Class Method Details
.from_refresh_token(refresh_token, client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) ⇒ AccessTokenAuthentication
Builds an AccessTokenAuthentication from a refresh token and client credentials, by refreshing into a new one.
20 21 22 23 24 25 26 27 28 |
# File 'lib/asana/authentication/oauth2/access_token_authentication.rb', line 20 def self.from_refresh_token(refresh_token, client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) client = Client.new(client_id: client_id, client_secret: client_secret, redirect_uri: redirect_uri) new(client.token_from_refresh_token(refresh_token)) end |
Instance Method Details
#configure(connection) ⇒ void
This method returns an undefined value.
Configures a Faraday connection injecting a bearer token, auto-refreshing it when needed.
44 45 46 47 |
# File 'lib/asana/authentication/oauth2/access_token_authentication.rb', line 44 def configure(connection) @token = @token.refresh! if @token.expired? connection.request :oauth2, @token.token end |