Class: TokenVerifier
- Inherits:
-
ActiveSupport::MessageVerifier
- Object
- ActiveSupport::MessageVerifier
- TokenVerifier
- Defined in:
- app/lib/token_verifier.rb
Overview
TODO:
use Rails.application.message_verifier
when possible
Generic token verifier with foodcoop scope
Defined Under Namespace
Classes: InvalidMessage, InvalidPrefix, InvalidScope
Class Method Summary collapse
Instance Method Summary collapse
- #generate(message = nil) ⇒ Object
-
#initialize(prefix) ⇒ TokenVerifier
constructor
A new instance of TokenVerifier.
- #verify(message) ⇒ Object
Constructor Details
#initialize(prefix) ⇒ TokenVerifier
Returns a new instance of TokenVerifier.
4 5 6 7 |
# File 'app/lib/token_verifier.rb', line 4 def initialize(prefix) super(self.class.secret) @_prefix = prefix.is_a?(Array) ? prefix.join(':') : prefix.to_s end |
Class Method Details
Instance Method Details
#generate(message = nil) ⇒ Object
9 10 11 12 13 |
# File 'app/lib/token_verifier.rb', line 9 def generate( = nil) = [FoodsoftConfig.scope, @_prefix] .append() unless .nil? super() end |
#verify(message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/lib/token_verifier.rb', line 15 def verify() r = super() raise InvalidMessage unless r.is_a?(Array) && r.length >= 2 && r.length <= 3 raise InvalidScope unless r[0] == FoodsoftConfig.scope raise InvalidPrefix unless r[1] == @_prefix # return original message return unless r.length > 2 r[2] end |