-
Notifications
You must be signed in to change notification settings - Fork 113
/
claims_builder.rb
39 lines (33 loc) · 1.03 KB
/
claims_builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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