Skip to content

Commit b690f40

Browse files
committed
Merge branch 'oauth2-manager' of https://github.com/sungwy/iceberg-python into oauth2-manager
2 parents 7dd0165 + 9223de0 commit b690f40

File tree

2 files changed

+20
-91
lines changed

2 files changed

+20
-91
lines changed

mkdocs/docs/configuration.md

Lines changed: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ The RESTCatalog supports pluggable authentication via the `auth` configuration b
388388

389389
- `noop`: No authentication (no Authorization header sent).
390390
- `basic`: HTTP Basic authentication.
391+
- `oauth2`: OAuth2 client credentials flow.
392+
- `legacyoauth2`: Legacy OAuth2 client credentials flow (Deprecated and will be removed in PyIceberg 1.0.0)
391393
- `custom`: Custom authentication manager (requires `auth.impl`).
392394
- `google`: Google Authentication support
393395

@@ -411,9 +413,10 @@ catalog:
411413

412414
| Property | Required | Description |
413415
|------------------|----------|-------------------------------------------------------------------------------------------------|
414-
| `auth.type` | Yes | The authentication type to use (`noop`, `basic`, or `custom`). |
416+
| `auth.type` | Yes | The authentication type to use (`noop`, `basic`, `oauth2`, or `custom`). |
415417
| `auth.impl` | Conditionally | The fully qualified class path for a custom AuthManager. Required if `auth.type` is `custom`. |
416418
| `auth.basic` | If type is `basic` | Block containing `username` and `password` for HTTP Basic authentication. |
419+
| `auth.oauth2` | If type is `oauth2` | Block containing OAuth2 configuration (see below). |
417420
| `auth.custom` | If type is `custom` | Block containing configuration for the custom AuthManager. |
418421
| `auth.google` | If type is `google` | Block containing `credentials_path` to a service account file (if using). Will default to using Application Default Credentials. |
419422

@@ -436,6 +439,20 @@ auth:
436439
password: mypass
437440
```
438441

442+
OAuth2 Authentication:
443+
444+
```yaml
445+
auth:
446+
type: oauth2
447+
oauth2:
448+
client_id: my-client-id
449+
client_secret: my-client-secret
450+
token_url: https://auth.example.com/oauth/token
451+
scope: read
452+
refresh_margin: 60 # (optional) seconds before expiry to refresh
453+
expires_in: 3600 # (optional) fallback if server does not provide
454+
```
455+
439456
Custom Authentication:
440457

441458
```yaml
@@ -451,7 +468,7 @@ auth:
451468

452469
- If `auth.type` is `custom`, you **must** specify `auth.impl` with the full class path to your custom AuthManager.
453470
- If `auth.type` is not `custom`, specifying `auth.impl` is not allowed.
454-
- The configuration block under each type (e.g., `basic`, `custom`) is passed as keyword arguments to the corresponding AuthManager.
471+
- The configuration block under each type (e.g., `basic`, `oauth2`, `custom`) is passed as keyword arguments to the corresponding AuthManager.
455472

456473
<!-- markdown-link-check-enable-->
457474

@@ -520,94 +537,6 @@ catalog:
520537
py-io-impl: pyiceberg.io.fsspec.FsspecFileIO
521538
```
522539

523-
#### Authentication in RESTCatalog
524-
525-
The RESTCatalog supports pluggable authentication via the `auth` configuration block. This allows you to specify which how the access token will be fetched and managed for use with the HTTP requests to the RESTCatalog server. The authentication method is selected by setting the `auth.type` property, and additional configuration can be provided as needed for each method.
526-
527-
##### Supported Authentication Types
528-
529-
- `noop`: No authentication (no Authorization header sent).
530-
- `basic`: HTTP Basic authentication.
531-
- `oauth2`: OAuth2 client credentials flow.
532-
- `legacyoauth2`: Legacy OAuth2 client credentials flow (Deprecated and will be removed in PyIceberg 1.0.0)
533-
- `custom`: Custom authentication manager (requires `auth.impl`).
534-
535-
##### Configuration Properties
536-
537-
The `auth` block is structured as follows:
538-
539-
```yaml
540-
catalog:
541-
default:
542-
type: rest
543-
uri: http://rest-catalog/ws/
544-
auth:
545-
type: <auth_type>
546-
<auth_type>:
547-
# Type-specific configuration
548-
impl: <custom_class_path> # Only for custom auth
549-
```
550-
551-
**Property Reference:**
552-
553-
| Property | Required | Description |
554-
|------------------|----------|-------------------------------------------------------------------------------------------------|
555-
| `auth.type` | Yes | The authentication type to use (`noop`, `basic`, `oauth2`, or `custom`). |
556-
| `auth.impl` | Conditionally | The fully qualified class path for a custom AuthManager. Required if `auth.type` is `custom`. |
557-
| `auth.basic` | If type is `basic` | Block containing `username` and `password` for HTTP Basic authentication. |
558-
| `auth.oauth2` | If type is `oauth2` | Block containing OAuth2 configuration (see below). |
559-
| `auth.custom` | If type is `custom` | Block containing configuration for the custom AuthManager. |
560-
561-
##### Examples
562-
563-
**No Authentication:**
564-
565-
```yaml
566-
auth:
567-
type: noop
568-
```
569-
570-
**Basic Authentication:**
571-
572-
```yaml
573-
auth:
574-
type: basic
575-
basic:
576-
username: myuser
577-
password: mypass
578-
```
579-
580-
**OAuth2 Authentication:**
581-
582-
```yaml
583-
auth:
584-
type: oauth2
585-
oauth2:
586-
client_id: my-client-id
587-
client_secret: my-client-secret
588-
token_url: https://auth.example.com/oauth/token
589-
scope: read
590-
refresh_margin: 60 # (optional) seconds before expiry to refresh
591-
expires_in: 3600 # (optional) fallback if server does not provide
592-
```
593-
594-
**Custom Authentication:**
595-
596-
```yaml
597-
auth:
598-
type: custom
599-
impl: mypackage.module.MyAuthManager
600-
custom:
601-
property1: value1
602-
property2: value2
603-
```
604-
605-
##### Notes
606-
607-
- If `auth.type` is `custom`, you **must** specify `auth.impl` with the full class path to your custom AuthManager.
608-
- If `auth.type` is not `custom`, specifying `auth.impl` is not allowed.
609-
- The configuration block under each type (e.g., `basic`, `oauth2`, `custom`) is passed as keyword arguments to the corresponding AuthManager.
610-
611540
### SQL Catalog
612541

613542
The SQL catalog requires a database for its backend. PyIceberg supports PostgreSQL and SQLite through psycopg2. The database connection has to be configured using the `uri` property. The init_catalog_tables is optional and defaults to True. If it is set to False, the catalog tables will not be created when the SQLCatalog is initialized. See SQLAlchemy's [documentation for URL format](https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls):

pyiceberg/catalog/rest/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def _refresh_token(self) -> None:
175175
expires_in = result.get("expires_in", self.expires_in)
176176
if expires_in is None:
177177
raise ValueError(
178-
"The expiration time of the Token must be provided by the Server in the Access Token Response in `expired_in` field, or by the PyIceberg Client."
178+
"The expiration time of the Token must be provided by the Server in the Access Token Response in `expires_in` field, or by the PyIceberg Client."
179179
)
180180
self._expires_at = time.time() + expires_in - self.refresh_margin
181181

0 commit comments

Comments
 (0)