Class: Cased::Authorization
- Inherits:
-
Object
- Object
- Cased::Authorization
- Defined in:
- app/models/cased/authorization.rb
Defined Under Namespace
Classes: MissingApplicationKey
Constant Summary collapse
- ALGORITHM =
'HS256'
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#issued_at ⇒ Object
readonly
Returns the value of attribute issued_at.
-
#issuer ⇒ Object
readonly
Returns the value of attribute issuer.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user:, user_id:, issued_at:, expires_at:, issuer:) ⇒ Authorization
constructor
A new instance of Authorization.
- #to_param ⇒ Object
- #to_s ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(user:, user_id:, issued_at:, expires_at:, issuer:) ⇒ Authorization
Returns a new instance of Authorization.
45 46 47 48 49 50 51 |
# File 'app/models/cased/authorization.rb', line 45 def initialize(user:, user_id:, issued_at:, expires_at:, issuer:) @user = user @user_id = user_id @issued_at = Time.at(issued_at) @expires_at = Time.at(expires_at) @issuer = issuer end |
Instance Attribute Details
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
42 43 44 |
# File 'app/models/cased/authorization.rb', line 42 def expires_at @expires_at end |
#issued_at ⇒ Object (readonly)
Returns the value of attribute issued_at.
41 42 43 |
# File 'app/models/cased/authorization.rb', line 41 def issued_at @issued_at end |
#issuer ⇒ Object (readonly)
Returns the value of attribute issuer.
43 44 45 |
# File 'app/models/cased/authorization.rb', line 43 def issuer @issuer end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
39 40 41 |
# File 'app/models/cased/authorization.rb', line 39 def user @user end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
40 41 42 |
# File 'app/models/cased/authorization.rb', line 40 def user_id @user_id end |
Class Method Details
.load!(token) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/cased/authorization.rb', line 19 def self.load!(token) raise MissingApplicationKey if Cased.config.guard_application_key.blank? # JWT.decode will raise here if the token has expired or the application # key does not match meaning it has been tampered with. data, = JWT.decode(token, Cased.config.guard_application_key, true, algorithm: ALGORITHM) new( user: data.fetch('user'), user_id: data.fetch('user_id'), expires_at: data.fetch('exp'), issuer: data.fetch('iss'), issued_at: data.fetch('iat'), ) end |
.validate!(token) ⇒ Object
35 36 37 |
# File 'app/models/cased/authorization.rb', line 35 def self.validate!(token) load!(token) end |
Instance Method Details
#to_param ⇒ Object
61 62 63 |
# File 'app/models/cased/authorization.rb', line 61 def to_param user_id end |
#to_s ⇒ Object
57 58 59 |
# File 'app/models/cased/authorization.rb', line 57 def to_s user end |
#token ⇒ Object
53 54 55 |
# File 'app/models/cased/authorization.rb', line 53 def token user_id end |