Uh oh!
There was an error while loading. Please reload this page.
feat: add OAuth PKCE helper functions and example usage - #584
Open
rajarshidattapy wants to merge 1 commit into
Open
feat: add OAuth PKCE helper functions and example usage#584rajarshidattapy wants to merge 1 commit into
rajarshidattapy wants to merge 1 commit into
Conversation
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 freeto 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.
Fixes#583.
Problem
examples/oauth_pkce_example.py— the repository's only example — has been dead onmainsince April:
05f81a5added two hand-written helper modules undersrc/openrouter/utils/plus theirexports in
utils/__init__.py.e6b0242("clean up removed docs and update generated SDKfiles") deleted both modules and the exports as part of a regeneration, and touched nothing
under
examples/. The commit message indicates collateral damage rather than an intentionalremoval, so this restores the helpers instead of deleting the example.
Change
Public API is unchanged from what shipped in
05f81a5— same dataclasses, same functionsignatures. Only the import path moves, from
openrouter.utilstoopenrouter.pkce.Two bugs fixed rather than restored
Both were in the deleted code and are verified against the live site:
_get_server_url()appended/authto the API base,producing
https://openrouter.ai/api/v1/auth—curlreturns 404. The authorizationpage is on the site origin,
https://openrouter.ai/auth, which returns 307. The originis now derived with
urlspliton the configured server URL, so regional hosts(
eu.openrouter.ai) and custom base URLs keep working. Covered by a test.ParseResultcallback URLs were corrupted.callback_urlis typedUnion[str, ParseResult]but was rendered withstr(), which on aParseResultyieldsParseResult(scheme='https', netloc='app.example', ...)rather than the URL — so half thedeclared signature silently produced a garbage query parameter. Now uses
.geturl().Why this won't be deleted again
The helpers previously lived in
src/openrouter/utils/, a directory Speakeasy owns, andtheir exports were wired into the generated
utils/__init__.py. A regeneration was alwaysgoing to take them, and did.
This PR puts them in
src/openrouter/pkce.py, outside the generated tree, and modifies nogenerated file.
.genignoregainssrc/openrouter/pkce.pyandexamples.Genignoring the generated
utils/__init__.pyto preserve the old import path was consideredand rejected: that would freeze the file, so future generated utils would never be exported —
trading this bug for a slower one. Nothing depends on the old path, since the symbols have
been absent from the package for roughly four months.
Verification
uv run python examples/oauth_pkce_example.pyruns, and the URL it prints returns 307pytest tests/test_pkce.py— 6 passed (challenge/verifier round-trip against a hand-computedSHA-256, RFC 7636 length and charset validation, site-origin URL, custom
server_url, PKCEand limit params,
ParseResultrendering)mypy srcclean across 770 files,pylint src --rcfile pylintrc10.00/10,pyright src0 errorsNote
tests/test_pkce.pyneedsuv run --with pytestto run:pytestis not in thedevdependency group and
pr-validation.yamlhas no pytest step, so nothing in CI will executeit — the same situation as the two existing files in
tests/. That gap is out of scope here;happy to file it separately if useful.