Repository navigation
OAuth 2.0 token acquisition - #4
Merged
Merged
Conversation
An OAuth 2.0 auth helper fetches its access token itself, from any authorization server that follows the standard (RFC 6749), when a request that uses it is sent: client credentials, password, and authorization code with or without PKCE (SHA-256 or plain). Signing in opens the sign-in page in the browser; a loopback callback URL (localhost, 127.0.0.1 or [::1], or none for a free port) is received by TermRest itself (RFC 8252), and otherwise the address the browser ended on is pasted, its state checked. The client authenticates with HTTP Basic or in the form, as in Postman, or with a JWT client assertion (RFC 7523, private_key_jwt: TermRest's x-clientAssertion settings) signed with a registered client certificate's key, in RS, PS or ES 256/384/512, naming the certificate by its thumbprints (x5t#S256, x5t), and optionally a key ID and the chain (x5c). Tokens are kept in memory for the session, one per set of settings, and refreshed with the refresh token when they expire (a new one is fetched if the refresh is refused). Token requests go with the workspace's SSL verification, proxy, CA bundle and client certificate, follow no redirects, send no cookies and are not recorded; one that fails stops the request with the server's error. Until the token URL is set, the access token stored in the collection is sent, as before. Postman's extra token, auth and refresh parameters are sent. In the UI, the Auth tab's OAuth 2.0 form scrolls, shows the current token and when it expires, and has Get new token and Forget token; signing in waits in a dialog that opens the browser again, copies the address, or takes the address pasted. termrest send fetches tokens as it goes (the sign-in address is printed on stderr). Copy as cURL and send --curl add a token fetched earlier, or warn that there is none. A client certificate may have no URL patterns: it goes to no server, and signs client assertions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The README's new OAuth 2.0 section describes the grants, when a token is fetched, signing in with a loopback or pasted callback, client authentication (Basic, in the body, or a JWT signed with a client certificate), Postman's extra parameters, how token requests are sent, and Copy as cURL; it lists Postman's settings and TermRest's own (private_key_jwt and the x-clientAssertion settings), with an example. The features, the Auth bullet and the compatibility table point to it; the client certificates section says an entry without patterns signs client assertions, send --curl says it fetches no token, the tests include an OAuth 2.0 server, and the roadmap moves on to saving responses as Postman examples. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
Implements the roadmap item OAuth 2.0 token acquisition in a generic way. It works with any authorization server that follows the standard (RFC 6749), such as Keycloak, Okta, Auth0, Entra ID or your own, with no provider-specific presets. Saving responses as Postman examples, the rest of that roadmap item, will come in its own PR.
Core (
TermRest.Core.Auth, no new dependencies)S256orplain). The implicit grant is kept but not fetched, because RFC 9700 retires it.grant_type,accessTokenUrl,authUrl,redirect_uri,clientId,clientSecret,scope,state,code_verifier,challengeAlgorithm,client_authentication,refreshTokenUrl,headerPrefix,addTokenToandaccessToken.tokenRequestParams,authRequestParamsandrefreshRequestParamsare sent too, in the body, a header or the URL. They replace a built-in parameter of the same name.accessTokenis sent as before. Collections exported from Postman with a pasted token behave as they did.client_authentication: private_key_jwt, RFC 7523) is new. The JWT is signed with a certificate from the client-certificate registry.x5t#S256andx5t, with an optionalkidandx5cchain.aud(the token URL unless set),iss/sub,jti, andiat/nbf/exp(valid for 5 minutes).x-:x-clientAssertionCertificate,x-clientAssertionAlgorithm,x-clientAssertionKeyId,x-clientAssertionChainandx-clientAssertionAudience.localhost,127.0.0.1or[::1]), TermRest receives the code itself through an in-process listener (RFC 8252). An empty callback uses a free port on 127.0.0.1.stateis checked, server errors such asaccess_deniedare reported, and signing in times out after 5 minutes.Accept: application/json.--insecure), proxy, CA bundle and matching client certificate.OAuth 2.0: the token request to https://…/token failed: 401 Unauthorized — invalid_client: ….send --verbose) says where its token came from and when it expires.UI
CLI
termrest sendfetches tokens as needed. To sign in, it opens the browser, prints the address on stderr, and accepts the loopback callback or a pasted address. Without a terminal, it fails at once if nobody could complete the sign-in.send --curladds a token fetched earlier, or warns that there is none.certs listdescribes entries without URL patterns.Verification
state, refresh, RS256/PS256/ES256 assertions verified by the server, and errors.win-x64: no warnings; 20.73 MiB (+0.26 MiB).sendwith a PS256 client assertion against a local token server, andsnapshot.