Sha256: a47b68739d73a55ab824b6dce25f768d91b15a67c40eca580f501a765b07e9d1

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require "rodauth/oauth"
require "rodauth/oauth/http_extensions"

module Rodauth
  Feature.define(:oauth_jwt_jwks, :OauthJwtJwks) do
    depends :oauth_jwt_base

    auth_methods(:jwks_set)

    auth_server_route(:jwks) do |r|
      before_jwks_route

      r.get do
        json_response_success({ keys: jwks_set }, true)
      end
    end

    private

    def oauth_server_metadata_body(path = nil)
      metadata = super
      metadata.merge!(jwks_uri: jwks_url)
      metadata
    end

    def jwks_set
      @jwks_set ||= [
        *(
          unless oauth_jwt_public_keys.empty?
            oauth_jwt_public_keys.flat_map { |algo, pkeys| Array(pkeys).map { |pkey| jwk_export(pkey).merge(use: "sig", alg: algo) } }
          end
        ),
        *(
          unless oauth_jwt_jwe_public_keys.empty?
            oauth_jwt_jwe_public_keys.flat_map do |(algo, _enc), pkeys|
              Array(pkeys).map do |pkey|
                jwk_export(pkey).merge(use: "enc", alg: algo)
              end
            end
          end
        )
      ].compact
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rodauth-oauth-1.6.3 lib/rodauth/features/oauth_jwt_jwks.rb
rodauth-oauth-1.6.2 lib/rodauth/features/oauth_jwt_jwks.rb
rodauth-oauth-1.6.0 lib/rodauth/features/oauth_jwt_jwks.rb
rodauth-oauth-1.5.0 lib/rodauth/features/oauth_jwt_jwks.rb
rodauth-oauth-1.4.0 lib/rodauth/features/oauth_jwt_jwks.rb