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, expiration = JWTSessions.refresh_expiration) ⇒ Object
- .destroy(uid, store, namespace) ⇒ Object
-
.find(uid, store, namespace = nil, first_match: false) ⇒ Object
first_match should be set to true when we need to search through the all namespaces.
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, nil) || SecureRandom.uuid @expiration = .fetch(:expiration, nil) || 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
37 38 39 40 41 42 |
# File 'lib/jwt_sessions/refresh_token.rb', line 37 def all(namespace, store) tokens = store.all_refresh_tokens(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, expiration = JWTSessions.refresh_expiration) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/jwt_sessions/refresh_token.rb', line 23 def create(csrf, access_uid, access_expiration, store, payload, namespace, expiration = JWTSessions.refresh_expiration) inst = new( csrf, access_uid, access_expiration, store, payload: payload, namespace: namespace, expiration: expiration ) inst.send(:persist_in_store) inst end |
.destroy(uid, store, namespace) ⇒ Object
52 53 54 |
# File 'lib/jwt_sessions/refresh_token.rb', line 52 def destroy(uid, store, namespace) store.destroy_refresh(uid, namespace) end |
.find(uid, store, namespace = nil, first_match: false) ⇒ Object
first_match should be set to true when we need to search through the all namespaces
46 47 48 49 50 |
# File 'lib/jwt_sessions/refresh_token.rb', line 46 def find(uid, store, namespace = nil, first_match: false) token_attrs = store.fetch_refresh(uid, namespace, first_match) raise Errors::Unauthorized, "Refresh token not found" if token_attrs.empty? build_with_token_attrs(store, uid, token_attrs, namespace) end |
Instance Method Details
#destroy ⇒ Object
85 86 87 |
# File 'lib/jwt_sessions/refresh_token.rb', line 85 def destroy store.destroy_refresh(uid, namespace) end |
#update(access_uid, access_expiration, csrf) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jwt_sessions/refresh_token.rb', line 72 def update(access_uid, access_expiration, csrf) @csrf = csrf @access_uid = access_uid @access_expiration = access_expiration store.update_refresh( uid: uid, access_expiration: access_expiration, access_uid: access_uid, csrf: csrf, namespace: namespace ) end |