Class: OmniAuth::Strategies::CodeSchool
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::CodeSchool
- Defined in:
- lib/oa-codeschool.rb
Overview
Authenticate to Code School with OAuth 2.0 and retrieve basic user information.
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #callback_phase ⇒ Object
-
#client ⇒ Object
memoize the client or else setting up Faraday stubs does not work.
-
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ CodeSchool
constructor
A new instance of CodeSchool.
- #request_phase ⇒ Object
- #user_data ⇒ Object
- #user_info ⇒ Object
Constructor Details
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ CodeSchool
Returns a new instance of CodeSchool.
21 22 23 24 25 26 27 |
# File 'lib/oa-codeschool.rb', line 21 def initialize(app, client_id = nil, client_secret = nil, = {}, &block) super(app, :code_school, client_id, client_secret, { :site => self.class.base_uri.presence || "http://localhost:3000", :authorize_url => "/oauth2/authorize", :token_url => "/oauth2/token" }, , &block) end |
Instance Method Details
#auth_hash ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/oa-codeschool.rb', line 57 def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user_data['id'], 'user_info' => user_info, 'extra' => {'user_hash' => user_data} }) end |
#callback_phase ⇒ Object
34 35 36 37 |
# File 'lib/oa-codeschool.rb', line 34 def callback_phase [:grant_type] ||= 'authorization_code' super end |
#client ⇒ Object
memoize the client or else setting up Faraday stubs does not work
44 45 46 |
# File 'lib/oa-codeschool.rb', line 44 def client @_client ||= super end |
#request_phase ⇒ Object
29 30 31 32 |
# File 'lib/oa-codeschool.rb', line 29 def request_phase [:response_type] ||= "code" super end |
#user_data ⇒ Object
39 40 41 |
# File 'lib/oa-codeschool.rb', line 39 def user_data @data ||= @access_token.get('/api/v2/user.json').parsed['user'] end |
#user_info ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/oa-codeschool.rb', line 48 def user_info { 'nickname' => user_data["username"], 'email' => user_data["email"], 'name' => user_data['name'], 'image' => user_data['avatar'] } end |