Class: Brine::ClientBuilding::OAuth2Params

Inherits:
Object
  • Object
show all
Defined in:
lib/brine/client_building.rb

Overview

Define OAuth2 middleware configuration.

This is essentially a thin wrapper around ‘github.com/oauth-xx/oauth2` to provide a mini-DSL and to facilitate the middleware configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOAuth2Params

Instantiate a new object with default attributes.



37
38
39
# File 'lib/brine/client_building.rb', line 37

def initialize
  @token_type = 'bearer'
end

Instance Attribute Details

#tokenObject

Store the token which has been retrieved from the authorization server.



25
26
27
# File 'lib/brine/client_building.rb', line 25

def token
  @token
end

#token_typeObject

Specify the type of OAuth2 token which will be retrieved.

Currently only ‘bearer` is supported.



32
33
34
# File 'lib/brine/client_building.rb', line 32

def token_type
  @token_type
end

Instance Method Details

#fetch_from(id, secret, opts) ⇒ Object

Fetch an OAuth2 token based on configuration and store as ‘token`.

The parameters are forwarded to OAuth2::Client.new which is used to retrieve the token.

Parameters:

  • id (String)

    Provide the login id credential with which to request authorization.

  • secret (String)

    Provide the secret credential with which to request authorization.

  • opts (Hash)

    Define options with which to create a client, see ‘github.com/oauth-xx/oauth2/blob/master/lib/oauth2/client.rb` for full details, common options will be duplicated here.

Options Hash (opts):

  • :site (String)

    Specify the OAuth2 authorization server from which to request a token.

  • :token_url (String)

    Specify the absolute or relative path to the Token endpoint on the authorization server.

  • :ssl (Hash)

    Provide SSL options to pass through to the transport client, ‘false` may be useful for self-signed certificates.



57
58
59
60
# File 'lib/brine/client_building.rb', line 57

def fetch_from(id, secret, opts)
  @token = OAuth2::Client.new(id, secret, opts)
    .client_credentials.get_token.token
end