class OmniAuth::Strategies::Blti

Public Class Methods

new(app, id, token, options={}) click to toggle source
Calls superclass method
# File lib/blti_omniauth.rb, line 11
def initialize(app, id, token, options={})
  @key = id
  @secret = token
  super(app, :blti, options)
end

Public Instance Methods

auth_hash() click to toggle source

normalize user’s data according to github.com/intridea/omniauth/wiki/Auth-Hash-Schema

Calls superclass method
# 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() click to toggle source
Calls superclass method
# 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() click to toggle source

redirect to OmniAuth’s callback (request is already authenticated)

# 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