Class: AtprotoAuth::State::TokenSet
- Inherits:
-
Object
- Object
- AtprotoAuth::State::TokenSet
- Defined in:
- lib/atproto_auth/state/token_set.rb
Overview
Represents a set of OAuth tokens and their associated metadata
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
-
#token_type ⇒ Object
readonly
Returns the value of attribute token_type.
Instance Method Summary collapse
-
#expired?(buffer = 30) ⇒ Boolean
Whether the access token has expired.
-
#initialize(access_token:, token_type:, expires_in:, scope:, sub:, refresh_token: nil) ⇒ TokenSet
constructor
Creates a new TokenSet from a token response.
-
#renewable? ⇒ Boolean
Whether this token set includes a refresh token.
Constructor Details
#initialize(access_token:, token_type:, expires_in:, scope:, sub:, refresh_token: nil) ⇒ TokenSet
Creates a new TokenSet from a token response
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/atproto_auth/state/token_set.rb', line 17 def initialize( # rubocop:disable Metrics/ParameterLists access_token:, token_type:, expires_in:, scope:, sub:, refresh_token: nil ) validate_token_type!(token_type) validate_required!("access_token", access_token) validate_required!("scope", scope) validate_required!("sub", sub) validate_expires_in!(expires_in) @access_token = access_token @refresh_token = refresh_token @token_type = token_type @scope = scope @sub = sub @expires_at = Time.now + expires_in end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/atproto_auth/state/token_set.rb', line 7 def access_token @access_token end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
7 8 9 |
# File 'lib/atproto_auth/state/token_set.rb', line 7 def expires_at @expires_at end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/atproto_auth/state/token_set.rb', line 7 def refresh_token @refresh_token end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
7 8 9 |
# File 'lib/atproto_auth/state/token_set.rb', line 7 def scope @scope end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
7 8 9 |
# File 'lib/atproto_auth/state/token_set.rb', line 7 def sub @sub end |
#token_type ⇒ Object (readonly)
Returns the value of attribute token_type.
7 8 9 |
# File 'lib/atproto_auth/state/token_set.rb', line 7 def token_type @token_type end |
Instance Method Details
#expired?(buffer = 30) ⇒ Boolean
Whether the access token has expired
47 48 49 |
# File 'lib/atproto_auth/state/token_set.rb', line 47 def expired?(buffer = 30) Time.now >= (@expires_at - buffer) end |
#renewable? ⇒ Boolean
Whether this token set includes a refresh token
41 42 43 |
# File 'lib/atproto_auth/state/token_set.rb', line 41 def renewable? !@refresh_token.nil? end |