Class: Masks::Rails::OpenID::IdToken

Inherits:
ApplicationRecord show all
Defined in:
app/models/masks/rails/openid/id_token.rb

Instance Method Summary collapse

Instance Method Details

#to_jwt(with = {}) ⇒ Object



35
36
37
38
39
# File 'app/models/masks/rails/openid/id_token.rb', line 35

def to_jwt(with = {})
  to_response_object(with).to_jwt(openid_client.private_key) do |jwt|
    jwt.kid = openid_client.kid
  end
end

#to_response_object(with = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/masks/rails/openid/id_token.rb', line 12

def to_response_object(with = {})
  subject =
    if openid_client.pairwise_subject?
      openid_client.subject_for(actor)
    else
      actor.actor_id
    end

  claims = {
    sub: subject,
    iss: openid_client.issuer,
    aud: openid_client.audience,
    exp: expires_at.to_i,
    iat: created_at.to_i,
    nonce:
  }

  id_token = OpenIDConnect::ResponseObject::IdToken.new(claims)
  id_token.code = with[:code] if with[:code]
  id_token.access_token = with[:access_token] if with[:access_token]
  id_token
end