โ† Glean-ia-acs ยท Day 44 of 56
Level 400 โ€” Builder ยท APIs30 minNIST GOVERN

Authentication โ€” Tokens, Scopes, and Identity

OAuth vs. Glean-issued tokens; user-scoped vs. global

You'll be able to

Read first

Day 2 Lab

  1. List your auth options: OAuth (your IdP issues the token) vs. a Glean-issued API token.
  2. Decide scope: user-scoped (acts as one person, honors their permissions) vs. global (acts across the instance).
  3. Pick the least-privilege option that still meets the need โ€” prefer user-scoped so per-user permissions are preserved.
  4. 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

Pick an answer โ€” you'll see if it's right and why.

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?

Pass threshold 80% ยท week 7 quiz

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.โ€

Next ยท Week 7 Day 3
The Search API