Class: JWTSessions::RefreshToken
- Inherits:
-
Object
- Object
- JWTSessions::RefreshToken
- Defined in:
- lib/jwt_sessions/refresh_token.rb
Instance Attribute Summary collapse
-
#access_expiration ⇒ Object
readonly
Returns the value of attribute access_expiration.
-
#access_uid ⇒ Object
readonly
Returns the value of attribute access_uid.
-
#csrf ⇒ Object
readonly
Returns the value of attribute csrf.
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
- .all(namespace, store) ⇒ Object
- .create(csrf, access_uid, access_expiration, store, payload, namespace) ⇒ Object
- .destroy(uid, store, namespace) ⇒ Object
- .find(uid, store, namespace = nil) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(csrf, access_uid, access_expiration, store, options = {}) ⇒ RefreshToken
constructor
A new instance of RefreshToken.
- #update(access_uid, access_expiration, csrf) ⇒ Object
Constructor Details
#initialize(csrf, access_uid, access_expiration, store, options = {}) ⇒ RefreshToken
Returns a new instance of RefreshToken.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jwt_sessions/refresh_token.rb', line 7 def initialize(csrf, access_uid, access_expiration, store, = {}) @csrf = csrf @access_uid = access_uid @access_expiration = access_expiration @store = store @uid = .fetch(:uid, SecureRandom.uuid) @expiration = .fetch(:expiration, JWTSessions.refresh_expiration) @namespace = .fetch(:namespace, nil) @token = Token.encode(.fetch(:payload, {}).merge('uid' => uid, 'exp' => expiration.to_i)) end |
Instance Attribute Details
#access_expiration ⇒ Object (readonly)
Returns the value of attribute access_expiration.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def access_expiration @access_expiration end |
#access_uid ⇒ Object (readonly)
Returns the value of attribute access_uid.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def access_uid @access_uid end |
#csrf ⇒ Object (readonly)
Returns the value of attribute csrf.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def csrf @csrf end |
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def expiration @expiration end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def namespace @namespace end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def store @store end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def token @token end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
5 6 7 |
# File 'lib/jwt_sessions/refresh_token.rb', line 5 def uid @uid end |
Class Method Details
.all(namespace, store) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/jwt_sessions/refresh_token.rb', line 29 def all(namespace, store) tokens = store.all_in_namespace(namespace) tokens.map do |uid, token_attrs| build_with_token_attrs(store, uid, token_attrs, namespace) end end |
.create(csrf, access_uid, access_expiration, store, payload, namespace) ⇒ Object
23 24 25 26 27 |
# File 'lib/jwt_sessions/refresh_token.rb', line 23 def create(csrf, access_uid, access_expiration, store, payload, namespace) inst = new(csrf, access_uid, access_expiration, store, payload: payload, namespace: namespace) inst.send(:persist_in_store) inst end |
.destroy(uid, store, namespace) ⇒ Object
42 43 44 |
# File 'lib/jwt_sessions/refresh_token.rb', line 42 def destroy(uid, store, namespace) store.destroy_refresh(uid, namespace) end |
.find(uid, store, namespace = nil) ⇒ Object
36 37 38 39 40 |
# File 'lib/jwt_sessions/refresh_token.rb', line 36 def find(uid, store, namespace = nil) token_attrs = store.fetch_refresh(uid, namespace) raise Errors::, 'Refresh token not found' if token_attrs.empty? build_with_token_attrs(store, uid, token_attrs, namespace) end |
Instance Method Details
#destroy ⇒ Object
67 68 69 |
# File 'lib/jwt_sessions/refresh_token.rb', line 67 def destroy store.destroy_refresh(uid, namespace) end |
#update(access_uid, access_expiration, csrf) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/jwt_sessions/refresh_token.rb', line 60 def update(access_uid, access_expiration, csrf) @csrf = csrf @access_uid = access_uid @access_expiration = access_expiration store.update_refresh(uid, access_expiration, access_uid, csrf, namespace) end |