Class: OmniAuth::Strategies::Blti
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Blti
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/blti_omniauth.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, id, token, options = {}) ⇒ Blti
constructor
A new instance of Blti.
-
#request_phase ⇒ Object
redirect to OmniAuth’s callback (request is already authenticated).
Constructor Details
#initialize(app, id, token, options = {}) ⇒ Blti
Returns a new instance of Blti.
11 12 13 14 15 |
# File 'lib/blti_omniauth.rb', line 11 def initialize(app, id, token, ={}) @key = id @secret = token super(app, :blti, ) end |
Instance Method Details
#auth_hash ⇒ Object
normalize user’s data according to github.com/intridea/omniauth/wiki/Auth-Hash-Schema
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/blti_omniauth.rb', line 49 def auth_hash OmniAuth::Utils.deep_merge(super(), { 'uid' => @uid, 'user_info' => { 'name' => @username, 'nickname' => @nickname, 'image' => @avatar } }) end |
#callback_phase ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/blti_omniauth.rb', line 26 def callback_phase # create consumer with key and secret consumer = ::OAuth::Consumer.new(@key, @secret) # create token with token and secret token = ::OAuth::Token.new('', '') puts "BLTI: verifying signature" if ::OAuth::Signature.verify(request, { :consumer => consumer, :token => token} ) @uid = Base64.decode64(request.params['user_id']) @avatar = Base64.decode64(request.params['user_image']) @username = Base64.decode64(request.params['custom_fullname']) @nickname = Base64.decode64(request.params['lis_person_sourcedid']).split(':').last puts "BLTI: valid! uid=#{@uid}, avatar=#{@avatar}, username=#{@username}, nickname=#{@nickname}" # OmniAuth takes care of the rest super else puts "BLTI: fail!" # OmniAuth takes care of the rest fail!(:invalid_credentials) end end |
#request_phase ⇒ Object
redirect to OmniAuth’s callback (request is already authenticated)
18 19 20 21 22 23 24 |
# File 'lib/blti_omniauth.rb', line 18 def request_phase #r = Rack::Response.new #r.redirect callback_url # TODO falta pasar los parámetros #r.finish #session[:user_return_to] = full_host callback_call end |