Method: OAuth2::Client#initialize

Defined in:
lib/oauth2/client.rb

#initialize(client_id, client_secret, opts = {}) {|builder| ... } ⇒ Client

Instantiate a new OAuth 2.0 client using the Client ID and Client Secret registered to your application.

Parameters:

  • client_id (String)

    the client_id value

  • client_secret (String)

    the client_secret value

  • opts (Hash) (defaults to: {})

    the options to create the client with

Options Hash (opts):

  • :site (String)

    the OAuth2 provider site host

  • :authorize_url (String) — default: '/oauth/authorize'

    absolute or relative URL path to the Authorization endpoint

  • :token_url (String) — default: '/oauth/token'

    absolute or relative URL path to the Token endpoint

  • :token_method (Symbol) — default: :post

    HTTP method to use to request token (:get or :post)

  • :connection_opts (Hash) — default: {}

    Hash of connection options to pass to initialize Faraday with

  • :max_redirects (FixNum) — default: 5

    maximum number of redirects to follow

  • :raise_errors (Boolean) — default: true

    whether or not to raise an OAuth2::Error on responses with 400+ status codes

Yields:

  • (builder)

    The Faraday connection builder



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/oauth2/client.rb', line 25

def initialize(client_id, client_secret, opts={}, &block)
  @id = client_id
  @secret = client_secret
  @site = opts.delete(:site)
  ssl = opts.delete(:ssl)
  @options = {:authorize_url    => '/oauth/authorize',
              :token_url        => '/oauth/token',
              :token_method     => :post,
              :connection_opts  => {},
              :connection_build => block,
              :max_redirects    => 5,
              :raise_errors     => true}.merge(opts)
  @options[:connection_opts][:ssl] = ssl if ssl
end