Class: Devise::RpxConnectable::Strategies::RpxConnectable
- Inherits:
-
Strategies::Base
- Object
- Strategies::Base
- Devise::RpxConnectable::Strategies::RpxConnectable
- Defined in:
- lib/devise_rpx_connectable/strategy.rb
Overview
Default strategy for signing in a user using RPX. Redirects to sign_in page if it’s not authenticated
Instance Method Summary collapse
-
#authenticate! ⇒ Object
Authenticate user with RPX.
- #valid? ⇒ Boolean
Instance Method Details
#authenticate! ⇒ Object
Authenticate user with RPX.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/devise_rpx_connectable/strategy.rb', line 19 def authenticate! klass = mapping.to raise StandardError, "RPXNow API key is not defined, please see the documentation of RPXNow gem to setup it." unless RPXNow.api_key.present? begin rpx_user = (RPXNow.user_data(params[:token], :extended => klass.rpx_extended_user_data, :additional => klass.rpx_additional_user_data) rescue nil) fail!(:rpx_invalid) and return unless rpx_user if user = klass.authenticate_with_rpx(:identifier => rpx_user["identifier"]) success!(user) else if klass.rpx_auto_create_account? user = returning(klass.new) do |u| u.store_rpx_credentials!(rpx_user) u.on_before_rpx_connect(rpx_user) end begin user.save(false) user.on_after_rpx_connect(rpx_user) success!(user) rescue fail!(:rpx_invalid) end else fail!(:rpx_invalid) end end rescue => e fail!(e.) end end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/devise_rpx_connectable/strategy.rb', line 13 def valid? valid_controller? && valid_params? && mapping.to.respond_to?('authenticate_with_rpx') end |