Sha256: 65c3e3a6978837ea45babab761d60833d357690642ef249f71ac87545a52d807

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module Rack
  module OAuth2
    module Server
      module Extension
        module PKCE
          module AuthorizationRequest
            def self.included(klass)
              klass.send :attr_optional, :code_challenge, :code_challenge_method
            end

            def initialize(env)
              super
              @code_challenge = params['code_challenge']
              @code_challenge_method = params['code_challenge_method']
            end
          end

          module TokenRequest
            def self.included(klass)
              klass.send :attr_optional, :code_verifier
            end

            def initialize(env)
              super
              @code_verifier = params['code_verifier']
            end

            def verify_code_verifier!(code_challenge, code_challenge_method = :S256)
              if code_verifier.present? || code_challenge.present?
                case code_challenge_method&.to_sym
                when :S256
                  code_challenge == Util.urlsafe_base64_encode(
                    OpenSSL::Digest::SHA256.digest(code_verifier.to_s)
                  ) or invalid_grant!
                when :plain
                  code_challenge == code_verifier or invalid_grant!
                else
                  invalid_grant!
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-oauth2-2.2.1 lib/rack/oauth2/server/extension/pkce.rb
rack-oauth2-2.2.0 lib/rack/oauth2/server/extension/pkce.rb
rack-oauth2-2.1.0 lib/rack/oauth2/server/extension/pkce.rb