Class: OmniAuth::Strategies::Cobot

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth2/cobot.rb

Overview

Authenticate to Cobot utilizing OAuth 2.0 and retrieve basic user information.

Examples:

Basic Usage

use OmniAuth::Strategies::Cobot, 'Client ID', 'Client Secret'

Instance Attribute Summary

Attributes inherited from OAuth2

#client_id, #client_options, #client_secret, #options

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_url, #client

Constructor Details

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

Returns a new instance of Cobot.

Parameters:

  • app (Rack Application)

    standard middleware application parameter

  • client_id (String) (defaults to: nil)

    the application id as registered on Cobot

  • client_secret (String) (defaults to: nil)

    the application secret as registered on Cobot



15
16
17
18
19
20
21
# File 'lib/omniauth/strategies/oauth2/cobot.rb', line 15

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :authorize_url => 'https://www.cobot.me/oauth2/authorize',
    :token_url => 'https://www.cobot.me/oauth2/access_token'
  }
  super(app, :cobot, client_id, client_secret, client_options, {:scope => 'read write'}.merge(options), &block)
end

Instance Method Details

#auth_hashObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/omniauth/strategies/oauth2/cobot.rb', line 23

def auth_hash
  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => user_data['login'],
      'user_info' => ,
      'extra' => {
        'user_hash' => user_data,
      }
    }
  )
end

#build_access_tokenObject

OAuth2 by default uses 'Bearer %s' in the header



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

def build_access_token
  access_token = super
  access_token.options[:header_format] = "OAuth %s"
  access_token
end

#user_dataObject



35
36
37
# File 'lib/omniauth/strategies/oauth2/cobot.rb', line 35

def user_data
  @data ||= MultiJson.decode(@access_token.get('https://www.cobot.me/api/user').body)
end

#user_infoObject



46
47
48
49
50
51
# File 'lib/omniauth/strategies/oauth2/cobot.rb', line 46

def 
  {
    'name'  => user_data['login'],
    'email' => user_data['email']
  }
end