Module: TelphinApi::Authorization

Included in:
TelphinApi
Defined in:
lib/telphin_api/authorization.rb

Overview

Note:

TelphinApi::Authorization extends TelphinApi so these methods should be called from the latter.

A module containing the methods for authorization.

Constant Summary collapse

OPTIONS =

Authorization options.

{
    client: {
        token_url: '/oauth/token.php'
    },
    client_credentials: {
        'auth_scheme' => 'request_body'
    }
}

Instance Method Summary collapse

Instance Method Details

#authorization_urlObject

Not used for this strategy

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/telphin_api/authorization.rb', line 19

def authorization_url
  fail(NotImplementedError, 'The authorization endpoint is not used in this strategy')
end

#authorize(options = {}) ⇒ TelphinApi::Client

Authorization (getting the access token and building a TelphinApi::Client with it).

Returns:

Raises:

  • (ArgumentError)

    raises after receiving an unknown authorization type.



26
27
28
29
30
31
# File 'lib/telphin_api/authorization.rb', line 26

def authorize(options = {})
  options[:client_id] ||= TelphinApi.app_key
  options[:client_secret] ||= TelphinApi.app_secret
  token = client.client_credentials.get_token(options, OPTIONS[:client_credentials].dup)
  Client.new(token)
end