Class: JwtTokenAuth::AuthToken
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- JwtTokenAuth::AuthToken
- Includes:
- Claims
- Defined in:
- lib/jwt_token_auth/auth_token.rb
Overview
JWT doesn’t encrypt the payload, it only sings it. That means that you should not store secret information in the payload but information that should be verified.
Instance Attribute Summary collapse
-
#aud ⇒ String
The audience of the token.
-
#exp ⇒ UnixTimestamp
The expiration.
-
#iat ⇒ UnixTimestamp
The time the token was issued.
-
#iss ⇒ String
The issue of the token.
-
#jti ⇒ String
Unique identifier for the token.
-
#nbf ⇒ String
Time before which the token must not be accepted for processing.
-
#sub ⇒ String
The subject of the token.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(params = {}) ⇒ AuthToken
constructor
A new instance of AuthToken.
- #payload ⇒ Object
- #secret ⇒ Object
Methods included from Claims
Constructor Details
#initialize(params = {}) ⇒ AuthToken
Returns a new instance of AuthToken.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jwt_token_auth/auth_token.rb', line 22 def initialize(params = {}) params = { exp: Time.new.to_i + JwtTokenAuth.configuration.expiration_time, iat: Time.now.to_i }.merge(convert_keys_into_symbols(params)) @iss = params[:iss] @sub = params[:sub] @aud = params[:aud] @exp = params[:exp] @nbf = params[:nbf] @iat = params[:iat] @jti = params[:jti] __setobj__(params) end |
Instance Attribute Details
#aud ⇒ String
The audience of the token
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def aud @aud end |
#exp ⇒ UnixTimestamp
The expiration
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def exp @exp end |
#iat ⇒ UnixTimestamp
The time the token was issued
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def iat @iat end |
#iss ⇒ String
The issue of the token
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def iss @iss end |
#jti ⇒ String
Unique identifier for the token
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def jti @jti end |
#nbf ⇒ String
Time before which the token must not be accepted for processing
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def nbf @nbf end |
#sub ⇒ String
The subject of the token
17 18 19 |
# File 'lib/jwt_token_auth/auth_token.rb', line 17 def sub @sub end |
Class Method Details
.decode(encoded_token) ⇒ Object
52 53 54 55 56 |
# File 'lib/jwt_token_auth/auth_token.rb', line 52 def decode(encoded_token) AuthToken.new( JWT.decode(encoded_token, JwtTokenAuth.configuration.secret)[0] ) end |
Instance Method Details
#encode ⇒ Object
47 48 49 |
# File 'lib/jwt_token_auth/auth_token.rb', line 47 def encode JWT.encode(self, secret) end |
#payload ⇒ Object
43 44 45 |
# File 'lib/jwt_token_auth/auth_token.rb', line 43 def payload self.except *claims_symbols end |
#secret ⇒ Object
39 40 41 |
# File 'lib/jwt_token_auth/auth_token.rb', line 39 def secret JwtTokenAuth.configuration.secret end |