sitemapStandard Roles

Check user roles with automatic hierarchy support.

circle-info

When to use: When you need coarse access control like "is this user an admin?"

chevron-rightPrerequisiteshashtag
  • Completed Login

  • Have a user object from authentication

5-Line Core

from gl_iam.core.roles import StandardRole

if user.has_standard_role(StandardRole.ORG_ADMIN):
    print("User has admin access")
# Also true for PLATFORM_ADMIN (hierarchy)

Role Hierarchy

Role
Implies

PLATFORM_ADMIN

ORG_ADMIN, ORG_MEMBER

ORG_ADMIN

ORG_MEMBER

ORG_MEMBER

(none)

Higher roles automatically include lower role access.

Step-by-Step

1

Import Standard Roles

2

Check Role with Hierarchy

3

Check Exact Role

4

Get User's Roles

5

Expected Output

circle-check

Complete Example

Create standard_roles.py:

Run it:

Expected output:

Provider Mapping

GL IAM maps provider-specific roles to standard roles:

Provider
Admin
Member

PostgreSQL

org_admin

org_member

Stack Auth

$admin

$member

Keycloak

admin

member

Common Pitfalls

Pitfall
Solution

Forgetting hierarchy

Default respects hierarchy - admins pass member checks

Hard-coding role strings

Use StandardRole enum for provider independence

Wrong status code

Role check is authorization (403), not authentication (401)

Last updated

Was this helpful?