Class: AtprotoAuth::State::Session
- Inherits:
-
Object
- Object
- AtprotoAuth::State::Session
- Includes:
- MonitorMixin
- Defined in:
- lib/atproto_auth/state/session.rb
Overview
Tracks state for an OAuth authorization flow session
Instance Attribute Summary collapse
-
#auth_server ⇒ Object
readonly
Returns the value of attribute auth_server.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#did ⇒ Object
Returns the value of attribute did.
-
#pkce_challenge ⇒ Object
readonly
Returns the value of attribute pkce_challenge.
-
#pkce_verifier ⇒ Object
readonly
Returns the value of attribute pkce_verifier.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#state_token ⇒ Object
readonly
Returns the value of attribute state_token.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#authorization_server=(server) ⇒ void
Updates the authorization server for this session.
-
#authorized? ⇒ Boolean
Whether this session has valid access tokens.
-
#initialize(client_id:, scope:, auth_server: nil, did: nil) ⇒ Session
constructor
Creates a new OAuth session.
-
#renewable? ⇒ Boolean
Whether this session can refresh its tokens.
-
#validate_state(state) ⇒ Boolean
Validates a state token against this session.
Constructor Details
#initialize(client_id:, scope:, auth_server: nil, did: nil) ⇒ Session
Creates a new OAuth session
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/atproto_auth/state/session.rb', line 22 def initialize(client_id:, scope:, auth_server: nil, did: nil) super() # Initialize MonitorMixin @session_id = SecureRandom.uuid @state_token = SecureRandom.urlsafe_base64(32) @client_id = client_id @scope = scope @auth_server = auth_server @did = did # Generate PKCE values @pkce_verifier = PKCE.generate_verifier @pkce_challenge = PKCE.generate_challenge(@pkce_verifier) @tokens = nil end |
Instance Attribute Details
#auth_server ⇒ Object (readonly)
Returns the value of attribute auth_server.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def auth_server @auth_server end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def client_id @client_id end |
#did ⇒ Object
Returns the value of attribute did.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def did @did end |
#pkce_challenge ⇒ Object (readonly)
Returns the value of attribute pkce_challenge.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def pkce_challenge @pkce_challenge end |
#pkce_verifier ⇒ Object (readonly)
Returns the value of attribute pkce_verifier.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def pkce_verifier @pkce_verifier end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def scope @scope end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def session_id @session_id end |
#state_token ⇒ Object (readonly)
Returns the value of attribute state_token.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def state_token @state_token end |
#tokens ⇒ Object
Returns the value of attribute tokens.
13 14 15 |
# File 'lib/atproto_auth/state/session.rb', line 13 def tokens @tokens end |
Instance Method Details
#authorization_server=(server) ⇒ void
This method returns an undefined value.
Updates the authorization server for this session
43 44 45 46 47 48 49 50 51 |
# File 'lib/atproto_auth/state/session.rb', line 43 def (server) synchronize do if @auth_server && @auth_server.issuer != server.issuer raise SessionError, "Session already bound to different authorization server" end @auth_server = server end end |
#authorized? ⇒ Boolean
Whether this session has valid access tokens
80 81 82 83 84 |
# File 'lib/atproto_auth/state/session.rb', line 80 def synchronize do !@tokens.nil? && !@tokens.expired? end end |
#renewable? ⇒ Boolean
Whether this session can refresh its tokens
88 89 90 91 92 |
# File 'lib/atproto_auth/state/session.rb', line 88 def renewable? synchronize do !@tokens.nil? && @tokens.renewable? end end |
#validate_state(state) ⇒ Boolean
Validates a state token against this session
97 98 99 100 101 102 |
# File 'lib/atproto_auth/state/session.rb', line 97 def validate_state(state) return false unless state # Use secure comparison to prevent timing attacks secure_compare(@state_token, state) end |