Authentication โ Tokens, Scopes, and Identity
OAuth vs. Glean-issued tokens; user-scoped vs. global
You'll be able to
- Distinguish OAuth from Glean-issued tokens and user-scoped from global scope
- Choose the least-privilege token that still preserves per-user permissions
Read first
Day 2 Lab
- List your auth options: OAuth (your IdP issues the token) vs. a Glean-issued API token.
- Decide scope: user-scoped (acts as one person, honors their permissions) vs. global (acts across the instance).
- Pick the least-privilege option that still meets the need โ prefer user-scoped so per-user permissions are preserved.
- Note the gotcha: a global token bypasses per-user ACLs, so results are not filtered by who is asking.
Working Example: User-Scoped vs. Global
A user-scoped token carries the end user's identity, so Glean filters every result through that user's permissions. A global token does not โ use it only for server-side work that legitimately needs cross-user reach. Verified against authentication.
import os
from glean import Glean
# Least privilege: act AS a specific user. Glean enforces THEIR permissions,
# so the same query returns only what that user is allowed to see.
user_client = Glean(
instance=os.environ["GLEAN_INSTANCE"],
api_token=os.environ["GLEAN_API_TOKEN"],
actas_user=os.environ["END_USER_EMAIL"], # impersonate within allowed scope
)
# Global scope: omit the user. This bypasses per-user ACL filtering โ
# reserve it for trusted server-side jobs, never for end-user-facing queries.
global_client = Glean(
instance=os.environ["GLEAN_INSTANCE"],
api_token=os.environ["GLEAN_GLOBAL_TOKEN"],
)
Default to user-scoped. Reach for a global token only when the task truly needs cross-user reach, and gate it behind your own authorization. Verified against authentication.
Check for understanding
Why does a user-scoped token return different results for two users running the same query?
Check yourself
1. Which set of languages does Glean ship typed Developer Platform clients for?
2. Why does a user-scoped token return different results for two different users running the same query?
3. In a Chat API response, what do the citations tell you?
4. You need to make 10,000 support tickets searchable in Glean. Which API do you use?
5. When pushing documents through the Indexing API, why must you include permission metadata?
In 10 seconds
โTwo token kinds, two scopes. User-scoped tokens carry the caller's identity so Glean enforces that user's permissions. Global tokens see everything โ powerful, and exactly why you reach for them last.โ
The Search API