Module: Authhub::InstanceMethods

Defined in:
lib/authhub/helper.rb

Instance Method Summary collapse

Instance Method Details

#auth_with_authhubObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/authhub/helper.rb', line 23

def auth_with_authhub
	@authhub_user_id = session[:authhub_user_id]
	return unless @authhub_user_id.nil?
	u = "http://#{self.class.authhub_options[:authserver]}/app/" +
		"#{self.class.authhub_options[:app]}" +
		"/user.json?token=#{params[:token]}" +
		"&secret=#{self.class.authhub_options[:secret]}"
	logger.debug "authhub: #{u}"
	uri = URI.parse(u)
	user = JSON.parse(Net::HTTP.get(uri))
	if user['user'].nil?
		redirect_to "http://#{self.class.authhub_options[:server]}" +
			"/apps/users/token?app=#{self.class.authhub_options[:app]}"
	else
		@authhub_user_id = session[:authhub_user_id] = user['user']['id']
	end
end