Class: Sworn::Verifier
- Inherits:
-
Object
- Object
- Sworn::Verifier
- Defined in:
- lib/sworn/verifier.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#oauth ⇒ Object
Returns the value of attribute oauth.
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(request, options = {}) ⇒ Verifier
constructor
A new instance of Verifier.
- #replayed? ⇒ Boolean
- #unsigned? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(request, options = {}) ⇒ Verifier
Returns a new instance of Verifier.
5 6 7 8 9 |
# File 'lib/sworn/verifier.rb', line 5 def initialize(request, = {}) @config = .fetch(:config) { Sworn.configuration } @request = request @oauth = SimpleOAuth::Header.parse(request.env["HTTP_AUTHORIZATION"]) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/sworn/verifier.rb', line 3 def config @config end |
#oauth ⇒ Object
Returns the value of attribute oauth.
3 4 5 |
# File 'lib/sworn/verifier.rb', line 3 def oauth @oauth end |
#request ⇒ Object
Returns the value of attribute request.
3 4 5 |
# File 'lib/sworn/verifier.rb', line 3 def request @request end |
Instance Method Details
#expired? ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/sworn/verifier.rb', line 15 def expired? = oauth.fetch(:timestamp).to_i now = Time.now.to_i window = (now - config.max_drift .. now + config.max_drift) !window.include?() end |
#replayed? ⇒ Boolean
22 23 24 |
# File 'lib/sworn/verifier.rb', line 22 def replayed? config.replay_protector.replayed?(oauth) end |
#unsigned? ⇒ Boolean
11 12 13 |
# File 'lib/sworn/verifier.rb', line 11 def unsigned? oauth.empty? end |
#valid? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sworn/verifier.rb', line 26 def valid? consumer_key = oauth[:consumer_key] consumer_secret = config.consumers[consumer_key] access_token = oauth[:token] token_secret = config.tokens[access_token] valid = SimpleOAuth::Header.new( request.request_method, request.url, request.params, oauth ).valid?(:consumer_secret => consumer_secret, :token_secret => token_secret) end |