Class: OmniAuth::Strategies::Pixelation

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/generators/apit/templates/omniauth_initializer.rb

Instance Method Summary collapse

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, options = {})
  @secret = secret
  @auth_redirect = auth_redirect
  super(app, :pixelation, options)
end

Instance Method Details

#auth_hashObject

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_phaseObject



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_phaseObject

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