Class: BusinessInsightApiClient::Helpers::Authorization
- Inherits:
-
Object
- Object
- BusinessInsightApiClient::Helpers::Authorization
- Defined in:
- lib/business_insight_api_client/helpers/authorization.rb
Overview
Authorization helper, used as helper to interact with the OAuth2 authorization server.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ authorization_url: 'https://nedap-bi.com', client_id: '', client_secret: '' }
Instance Attribute Summary collapse
-
#authorization_url ⇒ URI
readonly
The uri of the authorization server.
-
#client_id ⇒ String
readonly
The client id.
-
#client_secret ⇒ String
readonly
The client secret.
-
#current_token ⇒ OAuth2:AccessToken
The access token.
Instance Method Summary collapse
-
#access_token_from_hash(options = {}) ⇒ OAuth2::AccessToken
Creates an AccessToken from hash.
-
#auth_code_authorize_url(params = {}) ⇒ Object
Creates an URL to the authorization endpoint of the provider.
-
#auth_code_token_from_access_grant(access_grant, params = {}, options = {}) ⇒ Object
Retrieve an access token given the specified validation code.
-
#client_credential_token ⇒ OAuth2::AccessToken
Returns the client credential token for the application.
-
#current_token_headers ⇒ Hash
The headers hash (includes Authorization token) as formatted with the configuration.
-
#initialize(options = {}) ⇒ Authorization
constructor
Creates a new authorization helper.
Constructor Details
#initialize(options = {}) ⇒ Authorization
Creates a new authorization helper
34 35 36 37 38 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 34 def initialize( = {}) @authorization_url = URI([:authorization_url] || DEFAULT_OPTIONS[:authorization_url]) @client_id = [:client_id] || DEFAULT_OPTIONS[:client_id] @client_secret = [:client_secret] || DEFAULT_OPTIONS[:client_secret] end |
Instance Attribute Details
#authorization_url ⇒ URI (readonly)
Returns the uri of the authorization server.
19 20 21 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 19 def @authorization_url end |
#client_id ⇒ String (readonly)
Returns the client id.
22 23 24 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 22 def client_id @client_id end |
#client_secret ⇒ String (readonly)
Returns the client secret.
25 26 27 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 25 def client_secret @client_secret end |
#current_token ⇒ OAuth2:AccessToken
Returns the access token.
16 17 18 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 16 def current_token @current_token end |
Instance Method Details
#access_token_from_hash(options = {}) ⇒ OAuth2::AccessToken
Creates an AccessToken from hash
82 83 84 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 82 def access_token_from_hash( = {}) OAuth2::AccessToken.new oauth_client, .delete(:token), end |
#auth_code_authorize_url(params = {}) ⇒ Object
Creates an URL to the authorization endpoint of the provider. When the user authorizes he will direct the user agent that follows this link to the redirect_uri.
57 58 59 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 57 def (params = {}) oauth_client.auth_code.(params) end |
#auth_code_token_from_access_grant(access_grant, params = {}, options = {}) ⇒ Object
Retrieve an access token given the specified validation code. When the token is verified it will direct the user agent that follows this link to the redirect_uri.
68 69 70 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 68 def auth_code_token_from_access_grant(access_grant, params={},={}) oauth_client.auth_code.get_token(access_grant,params,) end |
#client_credential_token ⇒ OAuth2::AccessToken
Returns the client credential token for the application.
41 42 43 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 41 def client_credential_token oauth_client.client_credentials.get_token end |
#current_token_headers ⇒ Hash
Returns the headers hash (includes Authorization token) as formatted with the configuration.
47 48 49 50 |
# File 'lib/business_insight_api_client/helpers/authorization.rb', line 47 def current_token_headers return {} if current_token.nil? current_token.headers end |