Repository navigation
Conversation
AsyncClient gains request_device_authorization, poll_device_token, and wait_for_device_token. Each request authenticates with a credential's client authentication or a public client_id. The loop waits through an injected clock, honors task cancellation, adds 5 seconds on slow_down, and stops on a network error, a 5xx, or a 429 with DevicePollError, whose interval resumes the loop. ClientSecret, WebIdentity, and WorkloadIdentity implement the new optional ClientAuthenticator protocol. WebIdentity takes a client_id option. refresh_token_grant and refresh_authorization accept a credential. AuthorizationServerMetadata types device_authorization_endpoint. PERMANENT_ERROR_CODES includes expired_token. ECO-486. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng as is The credential's client authentication runs outside the transport call, so an error it raises, including a NetworkError, is not wrapped in DevicePollError. Adds tests for device authorization spec rows 25 to 28: a malformed interval, a 5xx or 429 with an OAuth error body, a credential failure on a poll, and the request timeout under a longer caller deadline. ECO-486. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Release previewkeycardai-oauth 0.35.2 → 0.36.0 (minor)
No other package releases. This comment was automatically generated by the release preview workflow. |
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the OAuth 2.0 device authorization grant (RFC 8628) to
keycardai-oauth, per the Device Authorization Grant spec and its follow-up change (keycard-sdk-spec 43165b4, branchcasey/eco-480-device-grant-spec-followups). Linear: ECO-486 (parent ECO-480).What it adds
AsyncClient.request_device_authorization,poll_device_token, andwait_for_device_token. Async only, per the spec's Python divergence row.credential=or a publicclient_id=. The client'sauthstrategy is not used.wait_for_device_tokenwaits through the client's clock before every poll, adds 5 seconds onslow_down, and raisesexpired_tokenwithout sending when the next poll would start afterexpires_at.DevicePollError. This includes a 5xx or 429 with an OAuth error body. Itsintervalresumes the loop. The original error is__cause__.retryablefollows the cause.interval: a 4xx without an OAuth error body, or an error from the credential's client authentication.timeout. A caller deadline around the whole loop does not replace it.intervalthat is not a positive integer isinvalid_response.TokenResponse.rawkeeps the server'sresourcefield as received.metadata=skips discovery.DeviceAuthorization(pydantic model,expires_atis a timezone-aware datetime),DeviceAuthorizationError(invalid_grantnot retryable),DevicePollError.Clockprotocol andSystemClock.AsyncClient(clock=...).ClientAuthenticatorprotocol andClientAuthentication(headers and form fields). This is a separate optional capability.ApplicationCredentialis unchanged. A credential without it is aConfigErrorbefore any request.ClientSecret: Basic header for the issuer's zone. An unknown zone raisesKeyError.WebIdentity: a new assertion per call,audis the endpoint,iss/subare the newclient_idoption.audience_configdoes not apply.WorkloadIdentity: the source's token, plusclient_idwhen configured.WebIdentity(client_id=...). Token exchange uses the auth context'sresource_client_idwhen present and this option otherwise.set_client_configfalls back to it too.refresh_token_grant(credential=...)andrefresh_authorization(credential=...).credentialwithclient_id(orclient_secret) is aConfigError.refresh_authorization'sclient_idis now optional, and required only withoutcredential.AuthorizationServerMetadata.device_authorization_endpoint, parsed from discovery.expired_tokeninPERMANENT_ERROR_CODES, with a test that the set and the typed classification agree on every protocol error code.Spec unit test rows covered
tests/keycardai/oauth/test_device_authorization.py, test names start with the row).AsyncClient.refresh_token_grantandrefresh_authorization.tests/keycardai/oauth/server/test_client_authentication.py).Integration rows are not covered. They need a live zone.
just check,just typecheck, andjust test-coveragepass locally (oauth 791 passed, 90% coverage).Open questions
ValueError, as before. Client authentication withoutclient_idraisesConfigError. The spec calls both a configuration error. Changing the exchange path's exception type would break callers that catchValueError.expires_atand the poll waits. The discovery cache still readstime.time(). The base spec names token expiry and waits only.Notes
credentialis typedClientAuthenticator | ApplicationCredential, so the result ofdiscover_credential()type-checks. The capability is checked at run time.Not changed
keycardai-temporal(_client_auth_fields) andkeycardai.oauth.server.agent_grantstill lift client-auth fields from a prepared token-exchange request for the client-credentials grant. Both could callclient_authenticationinstead. Left for a follow-up, because it changes howWebIdentityresolves its client id on those paths.🤖 Generated with Claude Code