Class: JWTSessions::AccessToken
- Inherits:
-
Object
- Object
- JWTSessions::AccessToken
- Defined in:
- lib/jwt_sessions/access_token.rb
Instance Attribute Summary collapse
-
#csrf ⇒ Object
readonly
Returns the value of attribute csrf.
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
- .create(csrf, payload, store, expiration = JWTSessions.access_expiration) ⇒ Object
- .destroy(uid, store) ⇒ Object
-
.find(uid, store) ⇒ Object
AccessToken’s find method cannot be used to retrieve token’s payload or any other information but is intended to identify if the token is present and to retrieve session’s CSRF token.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(csrf, payload, store, uid = SecureRandom.uuid, expiration = JWTSessions.access_expiration) ⇒ AccessToken
constructor
A new instance of AccessToken.
- #refresh_uid ⇒ Object
- #refresh_uid=(uid) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(csrf, payload, store, uid = SecureRandom.uuid, expiration = JWTSessions.access_expiration) ⇒ AccessToken
Returns a new instance of AccessToken.
7 8 9 10 11 12 13 |
# File 'lib/jwt_sessions/access_token.rb', line 7 def initialize(csrf, payload, store, uid = SecureRandom.uuid, expiration = JWTSessions.access_expiration) @csrf = csrf @uid = uid @expiration = expiration @payload = payload.merge("uid" => uid, "exp" => expiration.to_i) @store = store end |
Instance Attribute Details
#csrf ⇒ Object (readonly)
Returns the value of attribute csrf.
5 6 7 |
# File 'lib/jwt_sessions/access_token.rb', line 5 def csrf @csrf end |
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
5 6 7 |
# File 'lib/jwt_sessions/access_token.rb', line 5 def expiration @expiration end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/jwt_sessions/access_token.rb', line 5 def payload @payload end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/jwt_sessions/access_token.rb', line 5 def store @store end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
5 6 7 |
# File 'lib/jwt_sessions/access_token.rb', line 5 def uid @uid end |
Class Method Details
.create(csrf, payload, store, expiration = JWTSessions.access_expiration) ⇒ Object
32 33 34 35 36 |
# File 'lib/jwt_sessions/access_token.rb', line 32 def create(csrf, payload, store, expiration = JWTSessions.access_expiration) new(csrf, payload, store, SecureRandom.uuid, expiration).tap do |inst| store.persist_access(inst.uid, inst.csrf, inst.expiration) end end |
.destroy(uid, store) ⇒ Object
38 39 40 |
# File 'lib/jwt_sessions/access_token.rb', line 38 def destroy(uid, store) store.destroy_access(uid) end |
.find(uid, store) ⇒ Object
AccessToken’s find method cannot be used to retrieve token’s payload or any other information but is intended to identify if the token is present and to retrieve session’s CSRF token
45 46 47 48 49 |
# File 'lib/jwt_sessions/access_token.rb', line 45 def find(uid, store) token_attrs = store.fetch_access(uid) raise Errors::Unauthorized, "Access token not found" if token_attrs.empty? build_with_token_attrs(store, uid, token_attrs) end |
Instance Method Details
#destroy ⇒ Object
15 16 17 |
# File 'lib/jwt_sessions/access_token.rb', line 15 def destroy store.destroy_access(uid) end |
#refresh_uid ⇒ Object
23 24 25 |
# File 'lib/jwt_sessions/access_token.rb', line 23 def refresh_uid payload["ruid"] end |
#refresh_uid=(uid) ⇒ Object
19 20 21 |
# File 'lib/jwt_sessions/access_token.rb', line 19 def refresh_uid=(uid) self.payload["ruid"] = uid end |