You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Python SDK currently supports these OIDC/OAuth flows for Directory bearer auth:
106
+
107
+
- Interactive login via Authorization Code + PKCE with a loopback callback
108
+
- Pre-issued access token via `DIRECTORY_CLIENT_AUTH_TOKEN`
109
+
110
+
Interactive PKCE sessions are cached in the same location as the Go client:
111
+
`$XDG_CONFIG_HOME/dirctl/auth-token.json` or `~/.config/dirctl/auth-token.json`.
112
+
Explicit pre-issued tokens are used directly and are not cached.
113
+
114
+
Use this mode when your deployment expects a **Bearer access token** on gRPC (for example via a gateway that validates OIDC tokens). Register your IdP application with a **redirect URI** that matches `oidc_redirect_uri` exactly (for example `http://localhost:8484/callback`). The SDK starts a short-lived HTTP server on loopback to receive the authorization redirect.
115
+
116
+
Some IdPs use **public clients** with PKCE; Authlib may still expect a `client_secret` value in configuration. In that case, use a **random placeholder** from environment variables, not a real secret in source code.
117
+
118
+
**Important:** The default in-repo Envoy authz stack validates **GitHub** tokens. OIDC access tokens from your IdP provider only work if your environment’s gateway or auth service is configured to accept them.
# Client construction does not start browser login automatically.
153
+
# Opens the system browser and completes PKCE on loopback:
154
+
try:
155
+
client.authenticate_oauth_pkce()
156
+
except OAuthPkceError as e:
157
+
print(f"Login failed: {e}")
158
+
```
159
+
160
+
gRPC transport to the Directory still uses **TLS with system trust anchors** (or `tls_ca_file` if set). `TLS_SKIP_VERIFY` applies to **HTTPS calls to the OIDC issuer** (discovery and token endpoint), not to relaxing gRPC TLS to the Directory.
161
+
162
+
If you need to force the TLS server name / authority used by gRPC, set
163
+
`DIRECTORY_CLIENT_TLS_SERVER_NAME`.
164
+
165
+
For non-interactive callers that already have an access token, skip PKCE entirely:
166
+
167
+
```python
168
+
from agntcy.dir_sdk.client import Client, Config
169
+
170
+
config = Config(
171
+
server_address="directory.example.com:443",
172
+
auth_mode="oidc",
173
+
auth_token="your-access-token",
174
+
)
175
+
client = Client(config)
176
+
```
177
+
178
+
If no explicit `auth_token` is provided, the SDK will also try to reuse a valid
179
+
cached interactive token from the shared `dirctl` cache path before you need to
180
+
run `client.authenticate_oauth_pkce()`.
181
+
182
+
## Error Handling
82
183
83
184
The SDK primarily raises `grpc.RpcError` exceptions for gRPC communication issues and `RuntimeError` for configuration problems:
84
185
85
186
```python
86
187
import grpc
87
-
from agntcy.dir_sdk.client import Client
188
+
from agntcy.dir_sdk.client import Client, OAuthPkceError
0 commit comments