auth
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| ApprovalRedirect pyt3client.models.auth `POST /oauth/mcp/decision` result (upstream `AuthMcpApprovalRedirect`). |
||
| EnvironmentDescriptor pyt3client.models.environment `GET /.well-known/t3/environment`. |
||
| McpTokenResult pyt3client.models.auth `POST /oauth/mcp/token` result (upstream `AuthMcpTokenResult`). |
||
| OAuthAuthorizationServerMetadata pyt3client.models.auth `GET /.well-known/oauth-authorization-server`. |
||
| RegisteredClient pyt3client.models.auth `POST /oauth/mcp/register` result (upstream `AuthMcpRegisteredClient`). |
||
| T3AuthError pyt3client.errors Signing in failed, or the server no longer accepts the credential. |
||
| T3Credentials pyt3client.models.auth What a successful sign-in yields; persist it to reconnect without pairing again. |
||
| T3HttpError pyt3client.errors The server answered with an unexpected HTTP status. |
||
| T3ProtocolError pyt3client.errors The server answered in a shape this client does not understand. |
🛈 DocStrings¶
Sign in to a T3 Code environment's /mcp endpoint without a browser.
T3 Code lets outside agents use its MCP server through OAuth 2.1
(authorization code + PKCE, dynamic client registration). Interactive clients
send the user to an approval page; this module does what the page does, with a
pairing code instead of a click. It is the same flow T3 Code itself uses to
link one environment to another: upstream PeerLinks.signIn in
apps/server/src/peer/PeerLinks.ts.
The flow:
GET /.well-known/t3/environmentpublic descriptor (environment id).POST /oauth/mcp/registerregister a public client (stateless).POST /oauth/mcp/decisionapprove with the pairing code; the answer is the redirect URL carryingcode.POST /oauth/mcp/tokenexchange code + PKCE verifier for a token.
Server side: apps/server/src/auth/mcpOAuthHttp.ts (routes) and
apps/server/src/auth/McpOAuth.ts (validation, approve, exchangeCode).
Get a pairing code on the host with t3 auth pairing create, or in the app via
Settings -> Sharing & access.
fetch_descriptor
async
¶
fetch_descriptor(base_url: str, *, http_client: AsyncClient | None = None) -> EnvironmentDescriptor
Read an environment's public descriptor; needs no credential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Environment origin, such as |
required |
http_client
|
AsyncClient | None
|
Client to reuse; a short-lived one is created otherwise. |
None
|
Source code in src/pyt3client/auth.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
pair
async
¶
pair(
base_url: str,
pairing_code: str,
*,
access: McpAccess = "auto",
client_name: str = DEFAULT_CLIENT_NAME,
http_client: AsyncClient | None = None
) -> T3Credentials
Sign in to an environment's /mcp with a one-time pairing code.
The code is spent by this call. The resulting session shows up in T3 Code
under Settings -> Sharing & access with client_name as its label, lasts
30 days, and does not renew.
Agents only send credentials over https or to localhost, so use a
loopback, Tailscale HTTPS or T3 Connect address. A plain-http LAN address
works technically but sends the code unencrypted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Environment origin, such as |
required |
pairing_code
|
str
|
Code from |
required |
access
|
McpAccess
|
Level to approve the client at. Must not exceed what the code grants. |
'auto'
|
client_name
|
str
|
Label the environment shows for this client. |
DEFAULT_CLIENT_NAME
|
http_client
|
AsyncClient | None
|
Client to reuse; a short-lived one is created otherwise. |
None
|
Raises:
| Type | Description |
|---|---|
T3AuthError
|
The environment rejected the code or the sign-in. |
T3HttpError
|
The address does not answer like a T3 Code environment. |
Source code in src/pyt3client/auth.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
parse_approval_code
¶
parse_approval_code(code: str) -> tuple[McpAccess, str] | None
Level and canonical form of an app approval code (AUTO-…), or None for a plain code.
Mirrors upstream parseMcpApprovalCode: matching ignores case and
surrounding space, and the canonical code is upper case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
A pairing code as shown by T3 Code. |
required |
Source code in src/pyt3client/auth.py
79 80 81 82 83 84 85 86 87 88 89 90 91 | |