You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds Better Auth device authorization to the Hono backend, building on the optional Better Auth foundation in PR #460.
This provides the backend flow needed for clients such as the Word taskpane or Google Docs add-on to authenticate through an external browser and receive a Bearer token through polling.
Changes
Add Better Auth's deviceAuthorization plugin
Add configurable comma-separated device client ID allowlist
Add /api/device browser approval page
Add explicit Google sign-in and Approve/Deny flow
Add debug-only taskpane simulator at /api/debug/device
Poll for device authorization without relying on cookies
Verify the returned Bearer token through /api/protected
Forward device client ID configuration through Docker Compose
Add local environment setup guidance
Security
The private device_code remains with the polling client
Only the public user_code is included in the approval URL
Access tokens are held in memory and are not persisted or displayed
Dynamic browser content uses textContent rather than innerHTML
An empty client-ID allowlist rejects all device requests
Approval requires an authenticated Google session and explicit user action
Verification
Better Auth migration created the deviceCode table
Backend typecheck passed
Backend build passed
Existing backend tests passed: 13/13
Backend Docker image built successfully with better-sqlite3
Complete the full flow manually through /api/debug/device
Verify approval, denial, expiration, and polling behavior
Scope
This PR does not:
Remove or modify Auth0
Integrate the flow into the production Word or Google Docs frontend
Protect existing OpenAI or logging routes
Enable Better Auth automatically in deployed environments
Add remote Jenkins credentials or run deployment migrations
Branching
This is a stacked PR based on feat/better-auth-backend-foundation from PR #460. After PR #460 merges, this PR can be rebased or have its base changed to main.
with the appropriate secrets filled in for the ...s.
Then I ran npx auth@latest migrate to get the db schema, then DEBUG=true npm run dev to get the dev server running in debug mode.
Then I went to https://localhost:3000/api/debug/device and clicked the button there.
I got an error from Google:
Error 400: invalid_request
The loopback flow has been blocked in order to keep users secure. Follow the Loopback IP Address flow migration guide linked in the developer docs below to migrate your app to an alternative method.
Request details: flowName=GeneralOAuthFlow Related developer documentation
The linked page doesn't seem to mention anything about auth during development.
How did you get this to work locally?
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
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
Adds Better Auth device authorization to the Hono backend, building on the optional Better Auth foundation in PR #460.
This provides the backend flow needed for clients such as the Word taskpane or Google Docs add-on to authenticate through an external browser and receive a Bearer token through polling.
Changes
deviceAuthorizationplugin/api/devicebrowser approval page/api/debug/device/api/protectedSecurity
device_coderemains with the polling clientuser_codeis included in the approval URLtextContentrather thaninnerHTMLVerification
deviceCodetablebetter-sqlite3/api/debug/deviceScope
This PR does not:
Branching
This is a stacked PR based on
feat/better-auth-backend-foundationfrom PR #460. After PR #460 merges, this PR can be rebased or have its base changed tomain.