Class: Legate::Auth::Scheme

Inherits:
Object
  • Object
show all
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.

Instance Method Summary collapse

Instance Method Details

#apply_to_request(request, credential) ⇒ Hash

Apply authentication to a request

Parameters:

Returns:

  • (Hash)

    The modified request with authentication applied

Raises:

  • (NotImplementedError)


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

Parameters:

  • response (Hash)

    The HTTP response to check

Returns:

  • (Boolean)

    True if the 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?

This method is abstract.

Builds an authorization URI for interactive authentication flows

Parameters:

  • config (Legate::Auth::Config)

    The authentication configuration

  • redirect_uri (String, nil)

    The redirect URI for the authorization request

  • state (String, nil)

    A state parameter for the authorization request

Returns:

  • (String, nil)

    The authorization URI, or nil if not applicable



85
86
87
# File 'lib/legate/auth/scheme.rb', line 85

def build_authorization_uri(_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

Parameters:

Returns:

Raises:



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

Parameters:

Returns:

Raises:



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

Parameters:

Returns:

  • (Boolean)

    True if the token was revoked successfully

Raises:

  • (Legate::Auth::TokenRevokeError)

    If the token cannot be revoked



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_typeSymbol

Get the type of authentication scheme

Returns:

  • (Symbol)

    The scheme type identifier

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)

    True if this scheme supports token refresh



29
30
31
# File 'lib/legate/auth/scheme.rb', line 29

def supports_refresh?
  false
end

#to_hHash

This method is abstract.

Returns a hash representation of the scheme

Returns:

  • (Hash)

    A hash containing the scheme configuration



69
70
71
# File 'lib/legate/auth/scheme.rb', line 69

def to_h
  { type: scheme_type }
end

#to_sString

Returns a string representation of the scheme

Returns:

  • (String)

    A string representing the scheme



75
76
77
# File 'lib/legate/auth/scheme.rb', line 75

def to_s
  "#{self.class.name}<#{scheme_type}>"
end

#validate!Object

This method is abstract.

Validates the scheme configuration

Raises:



62
63
64
# File 'lib/legate/auth/scheme.rb', line 62

def validate!
  raise NotImplementedError, 'Subclasses must implement validate!'
end