Feature: integrate Hanko auth login#537
Closed
andrea-chirillano wants to merge 64 commits intomainfrom
Closed
Conversation
… into login_hanko
…er has no Django mapping For Hanko auth, the web component (HankoAuthButton) handles redirects and onboarding — requireAuth must not call login() after a failed checkHankoAuth. This was causing a redirect loop on new deployments where the user has a valid Hanko session but hasn't completed onboarding yet.
… into login_hanko
… of hardcoded localhost
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.
This pull request requires in-depth review before merging.
This PR includes changes to the backend (Django), frontend (React/JS), infrastructure (Docker, nginx), and tests. Review carefully before approving.
Add Hanko SSO Authentication
Integrates Hanko SSO as an alternative to legacy OSM OAuth, enabling single sign-on across the HOT ecosystem via
login.hotosm.org.Key changes
AUTH_PROVIDERsetting (legacy|hanko) — default islegacy, existing deployments are unaffectedHankoAuthenticationDRF backend added toDEFAULT_AUTHENTICATION_CLASSES(takes priority, falls back to token/OAuth2)hotosm-authweb component (<hotosm-auth>) rendered in NavBar viaHankoAuthButton.js<hotosm/tool-menu>web component added to the layout (loaded from jsDelivr, fixed version)hotosm-auth[django])print()calls replaced withloggingthroughoutapi/views.pyis_superuser(legacy) andADMIN_EMAILSenv var (Hanko)New API Endpoints
/api/auth/me//api/v1/auth/status//api/v1/auth/onboarding//api/admin//api/v1/hotosm_auth_django)Legacy OAuth routes (
/osm/,/o/,/authorized) are only registered whenAUTH_PROVIDER=legacy.New Dependencies
hotosm-auth[django]==0.2.10tzdata@hotosm/hanko-auth@0.5.2@hotosm/tool-menu@0.2.6Required Environment Variables
Backend
AUTH_PROVIDERhankohankoto enable SSO. Default:legacyHANKO_API_URLhttps://login.hotosm.orgHANKO_PUBLIC_URLHANKO_API_URL)COOKIE_SECRET<shared-secret>COOKIE_DOMAIN.hotosm.org.hotosm.orgfor cross-subdomain SSOCOOKIE_SECUREtruenot DEBUGADMIN_EMAILSadmin@hotosm.orgis_superuserin Hanko modeRAW_DATA_API_PUBLIC_URLhttps://api.rawdata.hotosm.orgRAW_DATA_API_URL)Frontend (injected via Django template into
window.*)AUTH_PROVIDERHANKO_URLhanko-urlto<hotosm-auth>How It Works
Legacy mode (default)
AUTH_PROVIDER=legacy— no changes, continues using OSM OAuth withaccess-tokenheader.Hanko mode
login.hotosm.orgHankoAuthenticationDRF backend validates the JWT cookie viahotosm_auth_djangoGET /api/v1/auth/status/returnsneeds_onboarding: true→ onboarding flow startsTest Plan
AUTH_PROVIDER=legacyGET /api/v1/auth/status/returns correctauthenticatedandneeds_onboardingvaluesPOST /api/v1/exports/) works with Hanko JWT cookiehotosm_auth_djangoapp migrations apply correctly whenAUTH_PROVIDER=hankoBackward Compatibility
legacy— no action required for existing deploymentshankowhen ready by setting the environment variables above