Class: Warden::Strategies::Token
- Inherits:
-
Base
- Object
- Base
- Warden::Strategies::Token
- Defined in:
- lib/warden/strategies/token.rb
Constant Summary collapse
- VERSION =
"0.2.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
-
#config ⇒ Object
Returns the configuration data for the default user scope.
-
#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 17 18 |
# 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 uid = config[:user_id_param] || :user_id token = config[:user_token_param] || :token @id, @token = params[uid], 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
24 25 26 27 28 29 30 31 32 |
# File 'lib/warden/strategies/token.rb', line 24 def authenticate! user = User.where(id: id).first token = user.send(config[:token_name]) if user && secure_compare(token) success!(user) else fail!("Invalid user id or token") end end |
#config ⇒ Object
Returns the configuration data for the default user scope.
35 36 37 |
# File 'lib/warden/strategies/token.rb', line 35 def config env["warden"].config[:scope_defaults][:user][:config] end |
#valid? ⇒ Boolean
20 21 22 |
# File 'lib/warden/strategies/token.rb', line 20 def valid? id && token end |