Looker CORS API OAuth Pattern (Direct Browser Auth)
This skill describes the Direct Browser OAuth pattern for Looker. It allows frontend applications to authenticate users directly against a Looker instance and make secure API calls via CORS without requiring a custom backend proxy.
1. The Core Pattern
The pattern leverages Looker's built-in OAuth2 support with PKCE (Proof Key for Code Exchange) to safely perform the authentication flow entirely in the browser.
Architectural Components
- Browser Application: The frontend app that performs the OAuth flow and makes direct
fetchcalls to the Looker API. - Looker Auth Server: Handles user login, consent, and issues access tokens.
- Looker API: Serves data directly to the browser via CORS.
2. The OAuth2 + PKCE Flow
Because a browser application is a "public client" and cannot store secrets, PKCE is used to secure the authorization code exchange.
- Code Challenge Generation: The app generates a cryptographically random
code_verifierand its SHA-256 hash, thecode_challenge. - Redirect to Looker: The app redirects the user to Looker's
/authendpoint with parameters:client_id: The registered Looker OAuth Client ID.redirect_uri: The app's callback URL.code_challenge: The hashed verifier.scope: Typicallycors_api.
- User Consent: The user logs into Looker and approves the application's request for access.
- Authorization Code: Looker redirects back to the
redirect_uriwith anauthorization_code. - Token Exchange: The app sends the
authorization_codeand the originalcode_verifierto Looker's/api/tokenendpoint. - Direct API Access: Looker validates the verifier and issues an
access_token. The app uses this token in theAuthorization: Bearerheader for all subsequent API calls.
3. Implementation Requirements
Looker Configuration (Critical)
- OAuth Application Registration: The application must be registered in Looker (via API or Admin UI) to obtain a
client_id. - Redirect URI: The
redirect_uriused in the flow must exactly match one of the URIs registered in the Looker OAuth application settings. - Embedded Domain Allowlist: The origin of the application must be added to the Embedded Domain Allowlist (Admin > Embed) to allow CORS headers.
Security Requirements
- HTTPS: The application must be served over HTTPS. Looker will reject OAuth requests from non-secure origins (except
localhostin some development contexts). - PKCE Implementation: Use a robust library or the Looker SDK to handle the
code_verifierandcode_challengelogic to avoid implementation errors.
4. Why Use This Pattern?
- Zero Backend: No server-side code is needed to handle authentication or proxy requests.
- User-Centric Security: The user authenticates directly with Looker; the application never sees the user's credentials.
- Full API Access: The application acts on behalf of the logged-in user, inheriting their specific Looker permissions and data access.
5. Troubleshooting Common Pitfalls
- Invalid Client ID: Ensure the
client_idis correct and the application is properly registered in the specific Looker instance. - Redirect URI Mismatch: The most common error. Check for trailing slashes, protocol (http vs https), and exact path matching.
- Browser Crypto API: PKCE relies on
window.crypto. If the app is not on a "secure context" (HTTPS), these APIs may be unavailable. - CORS Preflight (OPTIONS): Ensure the application origin is in the Looker Embedded Domain Allowlist.