Class: OAuth2c::Grants::Assertion::JWTProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2c/grants/assertion.rb

Instance Method Summary collapse

Constructor Details

#initialize(alg, key, iss:, aud:, sub:, jti: SecureRandom.uuid, exp: Time.now + (5 * 60), nbf: Time.now - 1, iat: Time.now, **other_claims) ⇒ JWTProfile

Returns a new instance of JWTProfile.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oauth2c/grants/assertion.rb', line 22

def initialize(alg, key,
    iss:,
    aud:,
    sub:,
    jti: SecureRandom.uuid,
    exp: Time.now + (5 * 60),
    nbf: Time.now - 1,
    iat: Time.now,
    **other_claims
)
  @alg = alg
  @key = key

  @iss = iss
  @aud = aud
  @sub = sub
  @jti = jti
  @exp = exp
  @nbf = nbf
  @iat = iat

  @other_claims = other_claims
end

Instance Method Details

#assertionObject



50
51
52
# File 'lib/oauth2c/grants/assertion.rb', line 50

def assertion
  JWT.encode(claims, @key, @alg)
end

#claimsObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/oauth2c/grants/assertion.rb', line 54

def claims
  {
    iss: @iss,
    sub: @sub,
    aud: @aud,
    jti: @jti,
    exp: @exp && @exp.utc.to_i,
    nbf: @nbf && @nbf.utc.to_i,
    iat: @iat && @iat.utc.to_i,
    **@other_claims,
  }
end

#grant_typeObject



46
47
48
# File 'lib/oauth2c/grants/assertion.rb', line 46

def grant_type
  "urn:ietf:params:oauth:grant-type:jwt-bearer"
end