class Asana::Authentication::OAuth2::AccessTokenAuthentication

Public: A mechanism to authenticate with an OAuth2 access token (a bearer token and a refresh token) or just a refresh token.

Public Class Methods

from_refresh_token(refresh_token, client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) click to toggle source

Public: Builds an AccessTokenAuthentication from a refresh token and client credentials, by refreshing into a new one.

refresh_token - [String] a refresh token client_id - [String] the client id of the registered Asana API

Application.

client_secret - [String] the client secret of the registered Asana API

Application.

redirect_uri - [String] the redirect uri of the registered Asana API

Application.

Returns an [AccessTokenAuthentication] instance with a refreshed access token.

# 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
new(access_token) click to toggle source

Public: Initializes a new AccessTokenAuthentication.

access_token - [::OAuth2::AccessToken] An ::OAuth2::AccessToken

object.
# File lib/asana/authentication/oauth2/access_token_authentication.rb, line 34
def initialize(access_token)
  @token = access_token
end

Public Instance Methods

configure(connection) click to toggle source

Public: Configures a Faraday connection injecting a bearer token, auto-refreshing it when needed.

connection - [Faraday::Connection] the Faraday connection instance.

Returns nothing.

# 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