Sha256: 1ca8f7a2fc7c0865e0fe9b8cd57627ebaa555a54dcd5526235b44efd3eadc22a

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

module Doorkeeper
  module OpenidConnect
    class UserInfo
      include ActiveModel::Validations

      def initialize(resource_owner, scopes)
        @resource_owner = resource_owner
        @scopes = scopes
      end

      def claims
        base_claims.merge resource_owner_claims
      end

      def as_json(*_)
        claims
      end

      private

      def base_claims
        {
          sub: subject
        }
      end

      def resource_owner_claims
        Doorkeeper::OpenidConnect.configuration.claims.to_h.map do |name, claim|
          if @scopes.exists? claim.scope
            [name, @resource_owner.instance_eval(&claim.generator)]
          end
        end.compact.to_h
      end

      def subject
        @resource_owner.instance_eval(&Doorkeeper::OpenidConnect.configuration.subject).to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doorkeeper-openid_connect-1.1.0 lib/doorkeeper/openid_connect/user_info.rb