Sha256: e239927e88d0a14c52e56a0ab6df49461a604fe57b7c161798bc50a735bd9be3

Contents?: true

Size: 1.03 KB

Versions: 15

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'ostruct'

module Doorkeeper
  module OpenidConnect
    class ClaimsBuilder
      def self.generate(access_token, response)
        resource_owner = Doorkeeper::OpenidConnect.configuration.resource_owner_from_access_token.call(access_token)

        Doorkeeper::OpenidConnect.configuration.claims.to_h.map do |name, claim|
          if access_token.scopes.exists?(claim.scope) && claim.response.include?(response)
            [name, claim.generator.call(resource_owner, access_token.scopes, access_token)]
          end
        end.compact.to_h
      end

      def initialize(&block)
        @claims = OpenStruct.new
        instance_eval(&block)
      end

      def build
        @claims
      end

      def normal_claim(name, response: [:user_info], scope: nil, &block)
        @claims[name] =
          Claims::NormalClaim.new(
            name: name,
            response: response,
            scope: scope,
            generator: block
          )
      end
      alias claim normal_claim
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
doorkeeper-openid_connect-1.8.10 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.8 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.7 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.6 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.5 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.4 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.3 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.2 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.1 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.0 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.8.0.pre.rc1 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.7.5 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.7.4 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.7.3 lib/doorkeeper/openid_connect/claims_builder.rb
doorkeeper-openid_connect-1.7.2 lib/doorkeeper/openid_connect/claims_builder.rb