Signature
Parameters
The name of the claim (piece of information) to retrieve from the ID token
Return Value
The value of the requested claim, or NULL if not available or user is not logged in
Description
Theuser_info() function provides access to user information when using OIDC Single Sign-On. It extracts specific claims from the ID token issued by your identity provider.
This function only works when OIDC is configured in sqlpage.json. If OIDC is not configured or the user is not logged in, it returns NULL.
Common Claims
User Identity
Subject - Unique identifier for the user. Use this for database foreign keys.
Email - User’s email address (may not be verified)
Username - The username the user prefers
Personal Information
Full name - User’s complete name
First name - User’s given name
Last name - User’s family name
Profile picture URL - Link to user’s profile image
Examples
Personalized Welcome Message
Greet the user by name:User Profile Card
Display user information:Store User in Database
Create or update user record on first login:Role-Based Access Control
Use custom claims for authorization:User-Specific Content
Show content filtered by user:Conditional UI Elements
Show different navigation for logged-in users:Audit Logging
Track user actions:Available Claims
The exact claims available depend on your identity provider and requested scopes:Core Claims (Always Available)
sub- Unique user identifieriss- Issuer (identity provider URL)aud- Audience (your client ID)exp- Token expiration time (Unix timestamp)iat- Token issued time (Unix timestamp)
Standard Claims (Depends on Scopes)
Request these scopes in your OIDC configuration to get these claims: Profile scope:name,given_name,family_name,middle_namenickname,preferred_usernameprofile(profile page URL)picture(profile image URL)websitegender,birthdate,zoneinfo,localeupdated_at
emailemail_verified
phone_numberphone_number_verified
address(JSON object with street, city, country, etc.)
Custom Claims
Some identity providers allow custom claims:Security Best Practices
Always Use ‘sub’ for User Identification
sub?
- Guaranteed unique per user
- Never changes for a user
- Always present in ID tokens
- Not personally identifiable
Validate Email Verification
If you need to trust the email address:Check for NULL Values
Always handle missing claims:Troubleshooting
Claim Not Available
If a claim returns NULL:- Check OIDC is configured in
sqlpage.json - Verify user is logged in
- Check you requested the right scopes
- Use
sqlpage.user_info_token()to see all available claims - Check your identity provider’s documentation
Debugging Available Claims
Provider-Specific Notes
- Requires
emailandprofilescopes for most claims email_verifiedis always true for Google accountssubis stable but unique per client ID
Azure AD / Microsoft
- Uses
preferred_usernamefor email - Provides
rolesclaim for app roles - Supports custom claims through app registration
Keycloak
- Highly configurable claims
- Supports realm and client roles
- Can add custom user attributes as claims
Auth0
- Supports custom claims with namespacing
- Provides
user_metadataandapp_metadata - Claims can be customized via rules
Related Functions
- sqlpage.user_info_token() - Get entire ID token as JSON
- sqlpage.oidc_logout_url() - Generate secure logout URL
- sqlpage.basic_auth_username() - Alternative authentication method