Class: Warden::Strategies::Token
- Inherits:
-
Base
- Object
- Base
- Warden::Strategies::Token
- Defined in:
- lib/warden/strategies/token.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #authenticate! ⇒ Object
-
#initialize(env, scope = nil) ⇒ Token
constructor
A new instance of Token.
- #valid? ⇒ Boolean
Constructor Details
#initialize(env, scope = nil) ⇒ Token
Returns a new instance of Token.
8 9 10 11 12 13 14 15 16 |
# File 'lib/warden/strategies/token.rb', line 8 def initialize(env, scope=nil) super if request. && request. =~ /^Basic (.*)$/m @id, @token = Base64.decode64($1).split(/:/, 2) else @id, @token = params[:user_id], params[:token] end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/warden/strategies/token.rb', line 6 def id @id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/warden/strategies/token.rb', line 6 def token @token end |
Instance Method Details
#authenticate! ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/warden/strategies/token.rb', line 22 def authenticate! user = User.where(id: id).first if user && Token.secure_compare(user.auth_token) success!(user) else fail!("Invalid user id or token") end end |
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/warden/strategies/token.rb', line 18 def valid? id && token end |