datarobot_genai.core.utils.auth
auth
DRAppCtx
AuthContextHeaderHandler
Manages encoding and decoding of authorization context into JWT tokens.
This class provides a consistent interface for encoding auth context into JWT tokens and exchanging them via HTTP headers across multiple applications.
Source code in datarobot_genai/core/utils/auth.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
__init__
__init__(secret_key: str | None = None, algorithm: str = DEFAULT_ALGORITHM, validate_signature: bool = True) -> None
Initialize the handler.
Parameters
secret_key : Optional[str] Secret key for JWT encoding/decoding. If None, tokens will be unsigned (insecure). algorithm : str JWT algorithm. Default is "HS256". validate_signature : bool Whether to validate JWT signatures. Default is True.
Raises
ValueError If algorithm is 'none' (insecure).
Source code in datarobot_genai/core/utils/auth.py
get_header
Get the authorization context header with encoded JWT token.
Source code in datarobot_genai/core/utils/auth.py
encode
Encode the current authorization context into a JWT token.
Source code in datarobot_genai/core/utils/auth.py
decode
Decode a JWT token into the authorization context.
Source code in datarobot_genai/core/utils/auth.py
get_context
Extract and validate authorization context from headers.
Parameters
headers : Dict[str, str] HTTP headers containing the authorization context.
Returns
Optional[AuthCtx] Validated authorization context or None if validation fails.
Source code in datarobot_genai/core/utils/auth.py
TokenRetriever
Bases: Protocol
Protocol for OAuth token retrievers.
Source code in datarobot_genai/core/utils/auth.py
filter_identities
refresh_access_token
async
Refresh the access token for the given identity ID.
Parameters
identity_id : str The provider identity ID to refresh the token for.
Returns
OAuthToken The refreshed OAuth token.
Source code in datarobot_genai/core/utils/auth.py
DatarobotTokenRetriever
Retrieves OAuth tokens using the DataRobot platform.
Source code in datarobot_genai/core/utils/auth.py
filter_identities
Filter oauth2 identities to only those with provider_identity_id.
The provider_identity_id is required in order to identify the provider
and retrieve the access token from DataRobot OAuth Providers service.
Source code in datarobot_genai/core/utils/auth.py
refresh_access_token
async
Refresh the access token using DataRobot's OAuth client.
AuthlibTokenRetriever
Retrieves OAuth tokens from a generic Authlib-based endpoint.
Source code in datarobot_genai/core/utils/auth.py
filter_identities
Filter identities to only OAuth2 identities.
refresh_access_token
async
Retrieve an OAuth token via an HTTP POST request.
Parameters
identity : Identity The identity to retrieve the token for.
Returns
OAuthToken The retrieved OAuth token.
Source code in datarobot_genai/core/utils/auth.py
OAuthConfig
Bases: BaseModel
Configuration extracted from AuthCtx metadata for OAuth operations.
Source code in datarobot_genai/core/utils/auth.py
AsyncOAuthTokenProvider
Provides OAuth tokens for authorized users.
This class manages OAuth token retrieval for users with multiple identity providers. It uses either DataRobot or Authlib as the OAuth token storage and refresh backend based on the auth context metadata.
Source code in datarobot_genai/core/utils/auth.py
__init__
Initialize the provider with an authorization context.
Parameters
auth_ctx : AuthCtx The authorization context containing user identities and metadata.
Source code in datarobot_genai/core/utils/auth.py
get_token
async
Get an OAuth access token for the specified auth type and provider.
Parameters
auth_type : ToolAuth Authentication type (only OBO is supported). provider_type : str, optional The specific provider to use (e.g., 'google'). Required if multiple identities are available.
Returns
str The retrieved OAuth access token.
Raises
ValueError If the auth type is unsupported or if a suitable identity cannot be found.
Source code in datarobot_genai/core/utils/auth.py
create_token_retriever
Create a token retriever based on the OAuth configuration.
Parameters
config : OAuthConfig The OAuth configuration specifying implementation type and endpoints.
Returns
TokenRetriever The configured token retriever instance.