omniauth-focovirtual 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Focovirtual
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,7 +1,50 @@
1
1
  require "omniauth-focovirtual/version"
2
2
 
3
- module Omniauth
4
- module Focovirtual
5
- # Your code goes here...
3
+ require 'omniauth/core'
4
+ module OmniAuth
5
+ module Strategies
6
+ class FocoLogin
7
+ include OmniAuth::Strategy
8
+
9
+ # receive parameters from the strategy declaration and save them
10
+ def initialize(app, secret, auth_redirect, options = {})
11
+ @secret = secret
12
+ @auth_redirect = auth_redirect
13
+ super(app, :foco_login, options)
14
+ end
15
+
16
+ # redirect to the Pixelation website
17
+ def request_phase
18
+ r = Rack::Response.new
19
+ r.redirect @auth_redirect
20
+ r.finish
21
+ end
22
+
23
+ def callback_phase
24
+ uid, username, token = request.params["uid"], request.params["name"], request.params["token"]
25
+ sha1 = Digest::SHA1.hexdigest("a mix of #{@secret}, #{uid}, #{name}")
26
+
27
+ # check if the request comes from Pixelation or not
28
+ if sha1 == token
29
+ @uid, @username = uid, username
30
+ # OmniAuth takes care of the rest
31
+ super
32
+ else
33
+ # OmniAuth takes care of the rest
34
+ fail!(:invalid_credentials)
35
+ end
36
+ end
37
+
38
+ # normalize user's data according to http://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
39
+ def auth_hash
40
+ OmniAuth::Utils.deep_merge(super(), {
41
+ 'uid' => @uid,
42
+ 'user_info' => {
43
+ 'name' => @username,
44
+ 'nickname' => @username
45
+ }
46
+ })
47
+ end
48
+ end
6
49
  end
7
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-focovirtual
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: