Class: Legate::Auth::Scheme
- Inherits:
-
Object
- Object
- Legate::Auth::Scheme
- Defined in:
- lib/legate/auth/scheme.rb
Overview
Base class for all authentication schemes. Schemes provide logic for applying authentication to requests, refreshing tokens, and other operations specific to their authentication type.
Direct Known Subclasses
Legate::Auth::Schemes::ApiKey, Legate::Auth::Schemes::HTTPBearer, Legate::Auth::Schemes::OAuth2, Legate::Auth::Schemes::ServiceAccount
Instance Method Summary collapse
-
#apply_to_request(request, credential) ⇒ Hash
Apply authentication to a request.
-
#authentication_error?(response) ⇒ Boolean
Checks if a response indicates an authentication error.
-
#build_authorization_uri(_config, _redirect_uri = nil, _state = nil) ⇒ String?
abstract
Builds an authorization URI for interactive authentication flows.
-
#exchange_token(credential) ⇒ Legate::Auth::ExchangedCredential
Exchange a credential for a token.
-
#refresh_token(token, credential) ⇒ Legate::Auth::ExchangedCredential
Refresh an authentication token.
-
#revoke_token(token, credential) ⇒ Boolean
Revoke a token.
-
#scheme_type ⇒ Symbol
Get the type of authentication scheme.
-
#supports_refresh? ⇒ Boolean
Check if this scheme supports token refresh.
-
#to_h ⇒ Hash
abstract
Returns a hash representation of the scheme.
-
#to_s ⇒ String
Returns a string representation of the scheme.
-
#validate! ⇒ Object
abstract
Validates the scheme configuration.
Instance Method Details
#apply_to_request(request, credential) ⇒ Hash
Apply authentication to a request
23 24 25 |
# File 'lib/legate/auth/scheme.rb', line 23 def apply_to_request(request, credential) raise NotImplementedError, "#{self.class} must implement #apply_to_request" end |
#authentication_error?(response) ⇒ Boolean
Checks if a response indicates an authentication error
92 93 94 95 96 97 |
# File 'lib/legate/auth/scheme.rb', line 92 def authentication_error?(response) return false unless response.is_a?(Hash) # HTTP status codes for auth errors (401 Unauthorized, 403 Forbidden) [401, 403].include?(response[:status]) end |
#build_authorization_uri(_config, _redirect_uri = nil, _state = nil) ⇒ String?
Builds an authorization URI for interactive authentication flows
85 86 87 |
# File 'lib/legate/auth/scheme.rb', line 85 def (_config, _redirect_uri = nil, _state = nil) nil # No-op in base class, override in subclasses that support interactive flows end |
#exchange_token(credential) ⇒ Legate::Auth::ExchangedCredential
Exchange a credential for a token
46 47 48 |
# File 'lib/legate/auth/scheme.rb', line 46 def exchange_token(credential) raise NotImplementedError, "#{self.class} does not support token exchange" end |
#refresh_token(token, credential) ⇒ Legate::Auth::ExchangedCredential
Refresh an authentication token
38 39 40 |
# File 'lib/legate/auth/scheme.rb', line 38 def refresh_token(token, credential) raise NotImplementedError, "#{self.class} does not support token refresh" end |
#revoke_token(token, credential) ⇒ Boolean
Revoke a token
55 56 57 |
# File 'lib/legate/auth/scheme.rb', line 55 def revoke_token(token, credential) raise NotImplementedError, "#{self.class} does not support token revocation" end |
#scheme_type ⇒ Symbol
Get the type of authentication scheme
15 16 17 |
# File 'lib/legate/auth/scheme.rb', line 15 def scheme_type raise NotImplementedError, "#{self.class} must implement #scheme_type" end |
#supports_refresh? ⇒ Boolean
Check if this scheme supports token refresh
29 30 31 |
# File 'lib/legate/auth/scheme.rb', line 29 def supports_refresh? false end |
#to_h ⇒ Hash
Returns a hash representation of the scheme
69 70 71 |
# File 'lib/legate/auth/scheme.rb', line 69 def to_h { type: scheme_type } end |
#to_s ⇒ String
Returns a string representation of the scheme
75 76 77 |
# File 'lib/legate/auth/scheme.rb', line 75 def to_s "#{self.class.name}<#{scheme_type}>" end |
#validate! ⇒ Object
Validates the scheme configuration
62 63 64 |
# File 'lib/legate/auth/scheme.rb', line 62 def validate! raise NotImplementedError, 'Subclasses must implement validate!' end |