Sha256: 973f6210c73092f98565155798402cc61ddadc63e7d8ee229822663717a45d7c

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

module Rack
  module OAuth2
    class AccessToken
      class MAC
        class Verifier
          include AttrRequired, AttrOptional
          attr_required :algorithm

          class VerificationFailed < StandardError; end

          def initialize(attributes = {})
            (required_attributes + optional_attributes).each do |key|
              self.send :"#{key}=", attributes[key]
            end
            attr_missing!
          rescue AttrRequired::AttrMissing => e
            raise VerificationFailed.new("#{self.class.to_s.split('::').last} Invalid: #{e.message}")
          end

          def verify!(expected)
            if expected == self.calculate
              :verified
            else
              raise VerificationFailed.new("#{self.class.to_s.split('::').last} Invalid")
            end
          end

          private

          def hash_generator
            case algorithm.to_s
            when 'hmac-sha-1'
              OpenSSL::Digest::SHA1.new
            when 'hmac-sha-256'
              OpenSSL::Digest::SHA256.new
            else
              raise 'Unsupported Algorithm'
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rack-oauth2-0.8.4 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.8.3 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.8.2 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.8.1 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.8.0 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.8.0.alpha lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.7.0 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.6.9 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.6.8 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.6.7 lib/rack/oauth2/access_token/mac/verifier.rb