Module: Asana::Authentication::OAuth2

Defined in:
lib/asana/authentication/oauth2.rb,
lib/asana/authentication/oauth2/client.rb,
lib/asana/authentication/oauth2/access_token_authentication.rb,
lib/asana/authentication/oauth2/bearer_token_authentication.rb

Overview

Deals with OAuth2 authentication. Contains a function to get an access token throught a browserless authentication flow, needed for some applications such as CLI applications.

Defined Under Namespace

Classes: AccessTokenAuthentication, BearerTokenAuthentication, Client

Class Method Summary collapse

Class Method Details

.offline_flow(client_id: required('client_id'), client_secret: required('client_secret')) ⇒ Object

Note:

This function reads from STDIN and writes to STDOUT. It is meant to be used only within the context of a CLI application.

Retrieves an access token through an offline authentication flow. If your application can receive HTTP requests, you might want to opt for a browser-based flow and use the omniauth-asana gem instead.

Your registered application’s redirect_uri should be exactly “urn:ietf:wg:oauth:2.0:oob”.

Parameters:

  • client_id (String) (defaults to: required('client_id'))

    the client id of the registered Asana API application.

  • client_secret (String) (defaults to: required('client_secret'))

    the client secret of the registered Asana API application.

Returns:

  • an ::OAuth2::AccessToken object.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/asana/authentication/oauth2.rb', line 31

def offline_flow(client_id: required('client_id'),
                 client_secret: required('client_secret'))
  client = Client.new(client_id: client_id,
                      client_secret: client_secret,
                      redirect_uri: 'urn:ietf:wg:oauth:2.0:oob')
  $stdout.puts '1. Go to the following URL to authorize the  ' \
               "application: #{client.authorize_url}"
  $stdout.puts '2. Paste the authorization code here: '
  auth_code = $stdin.gets.chomp
  client.token_from_auth_code(auth_code)
end