class Asana::Authentication::OAuth2::Client
Public: Deals with the details of obtaining an OAuth2
authorization URL and obtaining access tokens from either authorization codes or refresh tokens.
Public Class Methods
new(client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri'))
click to toggle source
Public: Initializes a new client with client credentials associated with a registered Asana
API application.
client_id - [String] a client id from the registered application client_secret - [String] a client secret from the registered
application
redirect_uri - [String] a redirect uri from the registered
application
# File lib/asana/authentication/oauth2/client.rb, line 18 def initialize(client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) @client = ::OAuth2::Client.new(client_id, client_secret, site: 'https://app.asana.com', authorize_url: '/-/oauth_authorize', token_url: '/-/oauth_token') @redirect_uri = redirect_uri end
Public Instance Methods
token_from_auth_code(auth_code)
click to toggle source
Public: Retrieves a token from an authorization code.
Returns the [::OAuth2::AccessToken] token.
# File lib/asana/authentication/oauth2/client.rb, line 37 def token_from_auth_code(auth_code) @client.auth_code.get_token(auth_code, redirect_uri: @redirect_uri) end
token_from_refresh_token(token)
click to toggle source
Public: Retrieves a token from a refresh token.
Returns the refreshed [::OAuth2::AccessToken] token.
# File lib/asana/authentication/oauth2/client.rb, line 44 def token_from_refresh_token(token) ::OAuth2::AccessToken.new(@client, '', refresh_token: token).refresh! end