The core concept
The login page decides the OAuth flow based on user agent. When your login page loads, check if it’s running in Despia:Two complete flows
Web flow (standard OAuth)
When:userAgent doesn’t include ‘despia’
Flow:
- Login page → redirects to OAuth provider
- OAuth provider → redirects back to
/auth /authpage → sets session, navigates to/dashboard
Despia native flow
When:userAgent includes ‘despia’
Flow:
- Login page → calls
despia('oauth://...')to open native browser - OAuth provider → redirects to
/native-callback(in native browser) /native-callback→ extracts tokens, redirects to deeplink withoauth/prefix- Native app → intercepts deeplink, closes browser, navigates to
/auth /authpage → receives tokens from URL, sets session
Key differences
| Step | Web Flow | Despia Flow |
|---|---|---|
| Login page | window.location.href = oauthUrl | despia('oauth://?url=...') |
| OAuth redirect | → /auth | → /native-callback |
| Callback action | Set session, navigate | Redirect to deeplink |
| Deeplink | None | yourappdeeplink://oauth/auth?tokens |
| Browser closes | N/A | When deeplink called |
| Final landing | /auth (already there) | /auth (via deeplink) |
Apple Sign-In special handling
Apple Sign-In on iOS devices needs different handling:Troubleshooting
Browser session doesn’t open
Problem: User clicks login, nothing happens. Check:- OAuth URL not properly encoded: Use
encodeURIComponent() - Missing
yourappdeeplink://prefix:despia('oauth://?url=...')not justdespia(url) - Testing in web browser instead of Despia app
Browser doesn’t close after login
Problem: User completes OAuth, stuck in browser. Cause: Missingoauth/ prefix in deeplink.
Wrong:
oauth/ prefix in the deeplink is what tells Despia to close ASWebAuthenticationSession/Chrome Custom Tabs.
Tokens not reaching /auth page
Problem: Browser closes but user not logged in. Check /auth page:- Tokens not encoded in callback: Use
encodeURIComponent(token)when building deeplink - Reading from wrong place: Tokens are in query params (
?), not hash (#) - Not decoding: Use
decodeURIComponent()when parsing
Redirect URI mismatch
Problem: OAuth provider shows “redirect_uri mismatch” error. Cause: Callback URL not registered with OAuth provider. Fix:- For Despia flow: Register
https://yourapp.com/native-callback - For web flow: Register
https://yourapp.com/auth - URLs must match exactly (no trailing slash differences)
Hash tokens lost in SPA routing
Problem: Tokens disappear from URL hash. Solution: Create static HTML callback page. Create /native-callback.html:Complete implementation
1. Login page (handles both flows):Debug checklist
When OAuth isn’t working: On login page:- Check user agent:
console.log(navigator.userAgent) - Verify correct flow selected
- Verify OAuth URL is valid
- Verify OAuth URL is encoded
- Check page loads:
console.log('Callback loaded') - Check tokens received:
console.log('Token:', !!access_token) - Check deeplink format:
myapp://oauth/auth?... - Verify
oauth/prefix present
- Check URL:
console.log(window.location.href) - Check for code (web):
console.log('Code:', code) - Check for tokens (Despia):
console.log('Token:', access_token) - Verify tokens stored in localStorage
- Verify navigation to /dashboard happens
Remember
The login page determines the flow.- Check
navigator.userAgent.includes('despia') - If true → Despia flow with
despia('oauth://...')and/native-callback - If false → Web flow with standard redirect and
/auth
oauth/prefix is critical.
- Deeplink format:
yourappdeeplink://oauth/auth?tokens - Without
oauth/→ browser won’t close - With
oauth/→ browser closes and app receives tokens
- Check for
despia-iphoneordespia-ipad - Use direct redirect (no
oauth://prefix) - Native Apple dialog opens automatically
For support or questions, contact: [email protected]