class BusinessInsightApiClient::Helpers::Authorization
Authorization
helper, used as helper to interact with the OAuth2 authorization server.
Constants
- DEFAULT_OPTIONS
Attributes
@return [String] the client id
@return [String] the client secret
@return [OAuth2:AccessToken] the access token.
Public Class Methods
Creates a new authorization helper
@param [Hash] options the options to create the Authorization
Helper with. @option options [String] :authorization_url ('nedap-bi.com') the authorization url. @option options [String] :client_id ('') the client id @option options [String] :client_secret ('') the client secret @raise [URI::InvalidURIError] when the authorization_url
given can not be parsed into an uri.
# File lib/business_insight_api_client/helpers/authorization.rb, line 34 def initialize(options = {}) @authorization_url = URI(options[:authorization_url] || DEFAULT_OPTIONS[:authorization_url]) @client_id = options[:client_id] || DEFAULT_OPTIONS[:client_id] @client_secret = options[:client_secret] || DEFAULT_OPTIONS[:client_secret] end
Public Instance Methods
Creates an AccessToken from hash
@param [Hash] options the options to create the Access Token with @option options [String] :token token the Access Token value @option options [String] :refresh_token (nil) the refresh_token value @option options [FixNum, String] :expires_in (nil) the number of seconds in which the AccessToken will expire @option options [FixNum, String] :expires_at (nil) the epoch time in seconds in which AccessToken will expire @return [OAuth2::AccessToken] an access token that can be used for API requests. @see www.rubydoc.info/gems/oauth2/1.0.0/OAuth2/AccessToken OAuth2::AccessToken information
# File lib/business_insight_api_client/helpers/authorization.rb, line 82 def access_token_from_hash(options = {}) OAuth2::AccessToken.new oauth_client, options.delete(:token), options end
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.
@param [String] access_grant The Authorization
Code value (Access Grant) @param [Hash] params additional params @option params [String] :redirect_uri the redirect uri to which the client has to be redirected to. @param [Hash] options options
# File lib/business_insight_api_client/helpers/authorization.rb, line 68 def auth_code_token_from_access_grant(access_grant, params={}, options={}) oauth_client.auth_code.get_token(access_grant, params, options) end
@return [OAuth2::AccessToken] returns the client credential token for the application.
# File lib/business_insight_api_client/helpers/authorization.rb, line 41 def client_credential_token oauth_client.client_credentials.get_token end
@return [Hash] the headers hash (includes Authorization
token) as formatted with the configuration
# File lib/business_insight_api_client/helpers/authorization.rb, line 47 def current_token_headers return {} if current_token.nil? current_token.headers end
Private Instance Methods
# File lib/business_insight_api_client/helpers/authorization.rb, line 88 def oauth_client # raise_errors: false, to suppress OAuth2::Errors and to allow custom error handling @oauth_client ||= OAuth2::Client.new(@client_id, @client_secret, site: @authorization_url, raise_errors: false) end