Class: OmniAuth::Strategies::OAuth2

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/oauth2.rb

Overview

Authentication strategy for connecting with APIs constructed using the [OAuth 2.0 Specification](tools.ietf.org/html/draft-ietf-oauth-v2-10). You must generally register your application with the provider and utilize an application id and secret in order to authenticate using OAuth 2.0.

Defined Under Namespace

Classes: CallbackError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, name, client_id = nil, client_secret = nil, client_options = {}, options = {}, &block) ⇒ OAuth2

Returns a new instance of OAuth2.

Parameters:

  • app (Rack Application)

    standard middleware application argument

  • name (String)

    the name for this provider to be used in its URL, e.g. ‘/auth/name`

  • client_id (String) (defaults to: nil)

    the client/application ID of this provider

  • client_secret (String) (defaults to: nil)

    the client/application secret of this provider

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

    that will be passed through to the OAuth2::Client (see [oauth2 docs](rubydoc.info/gems/oauth2))



40
41
42
43
44
45
# File 'lib/omniauth/strategies/oauth2.rb', line 40

def initialize(app, name, client_id = nil, client_secret = nil, client_options = {}, options = {}, &block)
  self.client_id = client_id
  self.client_secret = client_secret
  self.client_options = client_options
  super
end

Instance Attribute Details

#client_idObject

The ‘OAuth2::Client` for this strategy.



19
20
21
# File 'lib/omniauth/strategies/oauth2.rb', line 19

def client_id
  @client_id
end

#client_optionsObject

The ‘OAuth2::Client` for this strategy.



19
20
21
# File 'lib/omniauth/strategies/oauth2.rb', line 19

def client_options
  @client_options
end

#client_secretObject

The ‘OAuth2::Client` for this strategy.



19
20
21
# File 'lib/omniauth/strategies/oauth2.rb', line 19

def client_secret
  @client_secret
end

#optionsObject

The options passed in to the strategy.



17
18
19
# File 'lib/omniauth/strategies/oauth2.rb', line 17

def options
  @options
end

Instance Method Details

#callback_urlObject



51
52
53
# File 'lib/omniauth/strategies/oauth2.rb', line 51

def callback_url
  full_host + callback_path
end

#clientObject



47
48
49
# File 'lib/omniauth/strategies/oauth2.rb', line 47

def client
  ::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
end