Class: OmniAuth::Strategies::Cobot
- Defined in:
- lib/omniauth/strategies/oauth2/cobot.rb
Overview
Authenticate to Cobot utilizing OAuth 2.0 and retrieve basic user information.
Instance Attribute Summary
Attributes inherited from OAuth2
#client_id, #client_options, #client_secret, #options
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#build_access_token ⇒ Object
OAuth2 by default uses 'Bearer %s' in the header.
-
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Cobot
constructor
A new instance of Cobot.
- #user_data ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth2
Constructor Details
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Cobot
Returns a new instance of 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, ={}, &block) = { :authorize_url => 'https://www.cobot.me/oauth2/authorize', :token_url => 'https://www.cobot.me/oauth2/access_token' } super(app, :cobot, client_id, client_secret, , {:scope => 'read write'}.merge(), &block) end |
Instance Method Details
#auth_hash ⇒ Object
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' => user_info, 'extra' => { 'user_hash' => user_data, } } ) end |
#build_access_token ⇒ Object
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.[:header_format] = "OAuth %s" access_token end |
#user_data ⇒ Object
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_info ⇒ Object
46 47 48 49 50 51 |
# File 'lib/omniauth/strategies/oauth2/cobot.rb', line 46 def user_info { 'name' => user_data['login'], 'email' => user_data['email'] } end |