Reference for hub_sdk/base/auth.py
Note
This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/base/auth.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
hub_sdk.base.auth.Auth
Represents an authentication manager for Ultralytics Hub API.
This class handles authentication using either an API key or ID token, providing methods to authenticate, authorize, and manage authentication state.
Attributes:
Name | Type | Description |
---|---|---|
api_key |
str | None
|
The API key used for authentication with the Hub API. |
id_token |
str | None
|
The authentication token received after successful authorization. |
Methods:
Name | Description |
---|---|
authenticate |
Attempt to authenticate with the server using either id_token or API key. |
get_auth_header |
Get the authentication header for making API requests. |
get_state |
Get the authentication state. |
set_api_key |
Set the API key for authentication. |
authorize |
Authorize the user by obtaining an idToken through email and password. |
Source code in hub_sdk/base/auth.py
authenticate
Attempt to authenticate with the server using either id_token or API key.
Makes a POST request to the authentication endpoint with the appropriate authentication header. Handles connection errors and request exceptions.
Returns:
Type | Description |
---|---|
bool
|
True if authentication is successful, False otherwise. |
Raises:
Type | Description |
---|---|
ConnectionError
|
If authentication fails or user has not authenticated locally. |
Source code in hub_sdk/base/auth.py
authorize
Authorize the user by obtaining an idToken through a POST request with email and password.
Makes a request to the Firebase authentication URL with the provided credentials. Handles connection errors and request exceptions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
email
|
str
|
User's email address. |
required |
password
|
str
|
User's password. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if authorization is successful, False otherwise. |
Source code in hub_sdk/base/auth.py
get_auth_header
Get the authentication header for making API requests.
Creates the appropriate header based on whether an ID token or API key is available.
Returns:
Type | Description |
---|---|
Optional[dict]
|
The authentication header if id_token or API key is set, None otherwise. |
Source code in hub_sdk/base/auth.py
get_state
Get the authentication state.
Returns:
Type | Description |
---|---|
bool
|
True if either id_token or API key is set, False otherwise. |
set_api_key
Set the API key for authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The API key string. |
required |