Class: OmniAuth::Strategies::CodeSchool
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::CodeSchool
- Defined in:
- lib/oa-codeschool.rb
Overview
Authenticate to Code School utilizing 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.
22 23 24 25 26 27 28 |
# File 'lib/oa-codeschool.rb', line 22 def initialize(app, client_id = nil, client_secret = nil, = {}, &block) super(app, :code_path, client_id, client_secret, { :site => self.class.base_uri.presence || "http://localhost:3000", :authorize_path => "/oauth/authorize", :access_token_path => "/oauth/token" }, , &block) end |
Instance Method Details
#auth_hash ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/oa-codeschool.rb', line 59 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
35 36 37 38 |
# File 'lib/oa-codeschool.rb', line 35 def callback_phase [:grant_type] ||= 'authorization_code' super end |
#client ⇒ Object
memoize the client or else setting up Faraday stubs does not work
45 46 47 |
# File 'lib/oa-codeschool.rb', line 45 def client @_client ||= super end |
#request_phase ⇒ Object
30 31 32 33 |
# File 'lib/oa-codeschool.rb', line 30 def request_phase [:response_type] ||= "code" super end |
#user_data ⇒ Object
40 41 42 |
# File 'lib/oa-codeschool.rb', line 40 def user_data @data ||= MultiJson.decode(@access_token.get('/api/v1/user.json', {}, {}))['user'] end |
#user_info ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/oa-codeschool.rb', line 49 def user_info { 'nickname' => user_data["twitter_name"], 'email' => (user_data["email"] if user_data["email"]), 'first_name' => user_data["name"].split(" ").first, 'last_name' => user_data["name"].split(" ").last, 'name' => user_data['name'] } end |