Class: Asana::Authentication::OAuth2::Client
- Inherits:
-
Object
- Object
- Asana::Authentication::OAuth2::Client
- Defined in:
- lib/asana/authentication/oauth2/client.rb
Overview
Deals with the details of obtaining an OAuth2 authorization URL and obtaining access tokens from either authorization codes or refresh tokens.
Instance Method Summary collapse
-
#authorize_url ⇒ String
Returns the String OAuth2 authorize URL.
-
#initialize(client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) ⇒ Client
constructor
Initializes a new client with client credentials associated with a registered Asana API application.
-
#token_from_auth_code(auth_code) ⇒ ::OAuth2::AccessToken
Retrieves a token from an authorization code.
-
#token_from_refresh_token(token) ⇒ ::OAuth2::AccessToken
Retrieves a token from a refresh token.
Constructor Details
#initialize(client_id: required('client_id'), client_secret: required('client_secret'), redirect_uri: required('redirect_uri')) ⇒ Client
Initializes a new client with client credentials associated with a registered Asana API application.
18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Method Details
#authorize_url ⇒ String
Returns the String OAuth2 authorize URL.
30 31 32 |
# File 'lib/asana/authentication/oauth2/client.rb', line 30 def @client.auth_code.(redirect_uri: @redirect_uri) end |
#token_from_auth_code(auth_code) ⇒ ::OAuth2::AccessToken
Retrieves a token from an authorization code.
37 38 39 |
# 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) ⇒ ::OAuth2::AccessToken
Retrieves a token from a refresh token.
44 45 46 |
# File 'lib/asana/authentication/oauth2/client.rb', line 44 def token_from_refresh_token(token) ::OAuth2::AccessToken.new(@client, '', refresh_token: token).refresh! end |