Sha256: 53d865ff298caf8728f3e3453eeb2e1fe2c891133d3a690bdb25a2c519fafecb

Contents?: true

Size: 1.76 KB

Versions: 25

Compression:

Stored size: 1.76 KB

Contents

require_relative 'oauth2/bearer_token_authentication'
require_relative 'oauth2/access_token_authentication'
require_relative 'oauth2/client'

module Asana
  module Authentication
    # Public: 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.
    module OAuth2
      module_function

      # Public: 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".
      #
      # client_id     - [String] the client id of the registered Asana API
      #                 application.
      # client_secret - [String] the client secret of the registered Asana API
      #                 application.
      #
      # Returns an ::OAuth2::AccessToken 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.
      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
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
asana-2.0.1 lib/asana/authentication/oauth2.rb
asana-2.0.0 lib/asana/authentication/oauth2.rb
asana-1.0.0 lib/asana/authentication/oauth2.rb
asana-0.10.13 lib/asana/authentication/oauth2.rb
asana-0.10.12 lib/asana/authentication/oauth2.rb
asana-0.10.3 lib/asana/authentication/oauth2.rb
asana-0.10.2 lib/asana/authentication/oauth2.rb
asana-0.10.1 lib/asana/authentication/oauth2.rb
asana-0.10.0 lib/asana/authentication/oauth2.rb
asana-0.9.3 lib/asana/authentication/oauth2.rb
asana-0.9.2 lib/asana/authentication/oauth2.rb
asana-0.9.1 lib/asana/authentication/oauth2.rb
asana-0.9.0 lib/asana/authentication/oauth2.rb
asana-0.8.1 lib/asana/authentication/oauth2.rb
asana-0.8.0 lib/asana/authentication/oauth2.rb
asana-0.6.3 lib/asana/authentication/oauth2.rb
asana-0.6.2 lib/asana/authentication/oauth2.rb
asana-0.6.0 lib/asana/authentication/oauth2.rb
asana-0.5.0 lib/asana/authentication/oauth2.rb
asana-0.4.0 lib/asana/authentication/oauth2.rb