Class: Twilio::JWT::BaseJWT
- Inherits:
-
Object
- Object
- Twilio::JWT::BaseJWT
show all
- Defined in:
- lib/twilio-ruby/jwt/jwt.rb
Instance Method Summary
collapse
Constructor Details
#initialize(secret_key: nil, issuer: nil, subject: nil, nbf: nil, ttl: 3600, valid_until: nil) ⇒ BaseJWT
valid_until overrides ttl if specified
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/twilio-ruby/jwt/jwt.rb', line 7
def initialize(secret_key: nil, issuer: nil, subject: nil, nbf: nil, ttl: 3600, valid_until: nil)
if secret_key.nil?
raise ArgumentError, 'JWT does not have a signing key'
end
@secret_key = secret_key
@issuer = issuer
@subject = subject
@algorithm = 'HS256'
@nbf = nbf
@ttl = ttl
@valid_until = valid_until
end
|
Instance Method Details
21
22
23
|
# File 'lib/twilio-ruby/jwt/jwt.rb', line 21
def
{}
end
|
#_generate_payload ⇒ Object
25
26
27
|
# File 'lib/twilio-ruby/jwt/jwt.rb', line 25
def _generate_payload
raise NotImplementedError
end
|
29
30
31
32
33
34
|
# File 'lib/twilio-ruby/jwt/jwt.rb', line 29
def
= .clone
['typ'] = 'JWT'
['alg'] = @algorithm
end
|
#payload ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/twilio-ruby/jwt/jwt.rb', line 36
def payload
payload = _generate_payload.clone
payload[:iss] = @issuer
payload[:nbf] = @nbf || Time.now.to_i
payload[:exp] = @valid_until.nil? ? Time.now.to_i + @ttl : @valid_until
payload[:sub] = @subject unless @subject.nil?
payload
end
|
#to_jwt ⇒ Object
Also known as:
to_s
47
48
49
|
# File 'lib/twilio-ruby/jwt/jwt.rb', line 47
def to_jwt
::JWT.encode payload, @secret_key, @algorithm,
end
|