Sha256: 9333cf6a2aa67a62b7614fa81092363f984bef888cf1114c64dea2345d178632

Contents?: true

Size: 1.15 KB

Versions: 40

Compression:

Stored size: 1.15 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.name.demodulize} Invalid: #{e.message}")
          end

          def verify!(expected)
            if expected == self.calculate
              :verified
            else
              raise VerificationFailed.new("#{self.class.name.demodulize} 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

40 entries across 40 versions & 2 rubygems

Version Path
rack-oauth2-1.1.1 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.1.0 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.10 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.9 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.8 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-revibe-1.0.7 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.7 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.6 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.5 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.4 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.3 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.2 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.1 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-1.0.0 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.14.9 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.14.8 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.14.7 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.14.4 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.14.3 lib/rack/oauth2/access_token/mac/verifier.rb
rack-oauth2-0.14.2 lib/rack/oauth2/access_token/mac/verifier.rb