Repository navigation
feat(auth): log in through the DualEntry OAuth server - #48
Open
maciejdziag wants to merge 1 commit into
Open
maciejdziag wants to merge 1 commit into
maciejdziag wants to merge 1 commit into
Conversation
auth login reads the authorization server metadata, signs in with PKCE and a 127.0.0.1 loopback redirect for the dualentry-cli client, and keeps the access and refresh tokens in the keychain. Requests send a bearer token, refresh it before it expires and once more on a 401. X_API_KEY from the environment still comes first. auth logout revokes the login on the server. Refs EOPS-635
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.
Summary
dualentry auth loginnow signs in through the DualEntry OAuth server instead of creating an API key. It reads the server metadata (RFC 8414), opens the browser withclient_id=dualentry-cli, PKCE (S256) and a127.0.0.1loopback redirect, and keeps the access and refresh tokens in the keychain. Requests sendAuthorization: Bearer, refresh before expiry and once on a 401.X_API_KEYfrom the environment still comes first.auth logoutrevokes the login on the server.Changes
/.well-known/oauth-authorization-server/auth/oauth(the issuer{api_url}/auth/oauth), then the bare well-known path. Metadata is accepted only when itsissueris the one the URL names (RFC 8414 §3.3), so the metadata of another server on the same host is refused. S256 must be supported.127.0.0.1on a port the system picks before the browser opens. The callback checksstateand theissparameter (RFC 9207), and shows a failure page on anerror. The token request is a form post withclient_id,code_verifier,redirect_uriandresource={api_url}/public(RFC 8707), so the token serves the public API only. The wait now really ends after 5 minutes.oauth_tokensin the keychain; the owner-only file fallback is created with mode 600. A login replaces an older one: an older OAuth login is revoked, an older stored API key is removed. A stored API key of an older version still works until the next login.OAuthBearerAuth(anhttpx.Auth) refreshes 60 s before expiry and once on a 401, then retries the request once. A refreshed pair is saved. When another CLI process refreshed first, it uses the saved pair instead of a spent refresh token. A refused refresh asks to log in again.Test plan
uv run pytest): 490 passed, 140 skipped (tests/test_integration.pyneeds an API key).tests/test_auth.pyhas 30 tests: discovery, the authorize URL, a full login against a real loopback server, refused callbacks (state, issuer, error), timeout, refresh, revocation, the bearer client, and theauthcommands.uv run ruff check .,uv run ruff format --check .)Artifacts
The new code against the production OAuth server, with values that cannot sign anyone in: it reads the metadata, sends the authorize request of a login, and calls the token and revocation endpoints with unknown values. The full browser sign-in needs a person at the keyboard and is not shown.
The authorize request goes on to the sign-in page, with no
error: the server acceptsclient_id=dualentry-cli, the127.0.0.1redirect on any port, S256 and theresource. The token endpoint reads the form and refuses only the unknown code.Visual Proof
Not required — CLI only, no web UI.
Change-set: EOPS-635
Depends on: dualentry/backend#15565
Refs EOPS-635