Class: OmniAuth::Strategies::Pixelation
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Pixelation
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/generators/apit/templates/omniauth_initializer.rb
Instance Method Summary collapse
-
#auth_hash ⇒ Object
normalize user’s data according to github.com/intridea/omniauth/wiki/Auth-Hash-Schema.
- #callback_phase ⇒ Object
-
#initialize(app, secret, auth_redirect, options = {}) ⇒ Pixelation
constructor
receive parameters from the strategy declaration and save them.
-
#request_phase ⇒ Object
redirect to the Pixelation website.
Constructor Details
#initialize(app, secret, auth_redirect, options = {}) ⇒ Pixelation
receive parameters from the strategy declaration and save them
12 13 14 15 16 |
# File 'lib/generators/apit/templates/omniauth_initializer.rb', line 12 def initialize(app, secret, auth_redirect, = {}) @secret = secret @auth_redirect = auth_redirect super(app, :pixelation, ) end |
Instance Method Details
#auth_hash ⇒ Object
normalize user’s data according to github.com/intridea/omniauth/wiki/Auth-Hash-Schema
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/apit/templates/omniauth_initializer.rb', line 41 def auth_hash OmniAuth::Utils.deep_merge(super(), { 'uid' => @uid, 'user_info' => { 'name' => @username, 'nickname' => @username, 'image' => @avatar } }) end |
#callback_phase ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generators/apit/templates/omniauth_initializer.rb', line 25 def callback_phase uid, username, avatar, token = request.params["uid"], request.params["username"], request.params["avatar"], request.params["token"] sha1 = Digest::SHA1.hexdigest("a mix of #{@secret}, #{uid}, #{username}, #{avatar}") # check if the request comes from Pixelation or not if sha1 == token @uid, @username, @avatar = uid, username, avatar # OmniAuth takes care of the rest super else # OmniAuth takes care of the rest fail!(:invalid_credentials) end end |
#request_phase ⇒ Object
redirect to the Pixelation website
19 20 21 22 23 |
# File 'lib/generators/apit/templates/omniauth_initializer.rb', line 19 def request_phase r = Rack::Response.new r.redirect @auth_redirect r.finish end |