feat(oauth-providers): add OpenStreetMap OAuth 2.0 provider - #2076
Open
smellman wants to merge 3 commits into
Open
feat(oauth-providers): add OpenStreetMap OAuth 2.0 provider#2076smellman wants to merge 3 commits into
smellman wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 0e7b1f4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Author
|
Test application: https://gist.github.com/smellman/536b56922ef3033e80e73284bf38fe7c |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2076 +/- ##
==========================================
+ Coverage 92.23% 92.39% +0.16%
==========================================
Files 116 119 +3
Lines 4122 4210 +88
Branches 1077 1096 +19
==========================================
+ Hits 3802 3890 +88
Misses 285 285
Partials 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Closes #2074.
Adds
openstreetmapAuth, exported as@hono/oauth-providers/openstreetmap, plus arevokeTokenhelper.Implementation notes
OpenStreetMap runs Doorkeeper, and a few of its
choices differ from the other providers in this package. Each decision below is backed by the
authorization server metadata
or by the openstreetmap-website source.
PKCE is always used, with the
S256challenge method. The server advertisescode_challenge_methods_supported: ["plain", "S256"], and Doorkeeper requires a code verifier forpublic clients. Sending the challenge unconditionally means the middleware works for both
confidential and public applications.
No refresh token, and the access token carries no
expires_in. OpenStreetMap's Doorkeeperconfig sets
access_token_expires_in niland leavesuse_refresh_tokendisabled, so tokens do notexpire and no refresh token is ever issued.
tokenis therefore{ token: string }andrefresh-tokenis not set.revokeTokenis exported instead, since revocation is the only way toinvalidate a token.
User details come from
GET /api/0.6/user/details.json. This carries much more than the OIDCuserinfoendpoint, but it needs theread_prefsscope —api_ability.rbhascan :details, User if scopes.include?("read_prefs")— so the README calls that out. TheOpenStreetMap API answers errors with a plain text body rather than JSON, so the response status is
checked before parsing (
authFlow.ts).skip_authorizationis excluded fromOpenStreetMapScope, andread_emailis documented asprivileged. Both live in
PRIVILEGED_SCOPESinlib/oauth.rband are only offered to applicationsregistered by a site administrator, so
user-openstreetmap.emailis normallyundefined.Testing
Unit tests use the existing msw setup: 11 cases covering the redirect URL and its PKCE parameters,
the custom
redirect_uriandstateoptions, CSRF protection (both a mismatched and an omittedstate), an invalid code, an API rejection of the token, the success path, and both revocationoutcomes.
Beyond that, the flow was run manually against the live openstreetmap.org authorization server —
authorization, token exchange, user lookup and revocation. The live response then corrected the
types:
contributor_terms.pdandmessagesare unconditional in_user.json.jbuilderfor arequest that gets past the
read_prefscheck, so both are required rather than optional.One trap worth recording for anyone testing this locally:
force_ssl_in_redirect_uriindoorkeeper.rbonly permits plain http for the hosts127.0.0.1and::1. A redirect URI ofhttp://localhost:3000/...is rejected at application registration time.The author should do the following, if applicable
pnpm changesetat the top of this repo and push the changeset