You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(userinfo): add getUserInfo() to auth0-auth-js and auth0-server-js (G8)
Adds OIDC /userinfo support to close the last gap (G8) in the node-auth0
authentication-separation parity set.
auth0-auth-js (stateless core):
- AuthClient.getUserInfo(options): live /userinfo fetch via openid-client
fetchUserInfo; optional expectedSubject (defaults to skipSubjectCheck).
- New UserInfoError (extends ApiError), GetUserInfoOptions, and an
auth0-owned UserInfoResponse interface (only `sub` required, catch-all
index signature) for a stable public contract independent of openid-client.
auth0-server-js (session layer):
- ServerClient.getUserInfo(storeOptions?): live fetch using the session's
access token (auto-refresh via getAccessToken). Throws MissingSessionError
on no session, missing user sub, or resolver-mode domain mismatch; resolves
the per-domain AuthClient in resolver mode. Always passes the session `sub`
as expectedSubject for an OIDC subject-consistency check. Re-exports
UserInfoError.
Tests: 12 auth-js + 11 server-js (MSW HTTP-layer). Docs: EXAMPLES.md in both
packages. Additive, minor bump; no breaking changes.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
When the verification is successful, the `sid` and `sub` claims will be returned. If not, an error will be thrown.
671
672
673
+
## Retrieving User Information
674
+
675
+
The SDK provides a method to retrieve user profile information from the OIDC `/userinfo` endpoint. This is useful when you need to fetch fresh user claims using an access token.
676
+
677
+
```ts
678
+
import { AuthClient } from'@auth0/auth0-auth-js';
679
+
680
+
constauthClient=newAuthClient({
681
+
domain: '<AUTH0_DOMAIN>',
682
+
clientId: '<AUTH0_CLIENT_ID>',
683
+
clientSecret: '<AUTH0_CLIENT_SECRET>',
684
+
});
685
+
686
+
// Retrieve user information with an access token
687
+
constuserInfo=awaitauthClient.getUserInfo({
688
+
accessToken: '<access_token>',
689
+
});
690
+
691
+
console.log(userInfo.sub);
692
+
console.log(userInfo.email);
693
+
console.log(userInfo.name);
694
+
```
695
+
696
+
The returned `UserInfoResponse` object contains OIDC standard claims like `sub`, `email`, `name`, and other profile information. The exact claims returned depend on the scopes requested during authentication and the user's profile data.
697
+
698
+
### Optional Subject Validation
699
+
700
+
You can optionally validate that the returned `sub` claim matches an expected value. This is useful for security checks:
701
+
702
+
```ts
703
+
constuserInfo=awaitauthClient.getUserInfo({
704
+
accessToken: myAccessToken,
705
+
expectedSubject: 'auth0|user123',
706
+
});
707
+
708
+
// If the returned sub doesn't match expectedSubject, getUserInfo() throws UserInfoError
709
+
```
710
+
711
+
If the `expectedSubject` parameter is not provided, subject validation is skipped.
712
+
713
+
### Error Handling
714
+
715
+
The `getUserInfo()` method throws `UserInfoError` when the request fails. Common error scenarios include:
716
+
717
+
- **401 Unauthorized**: The access token is expired, revoked, or invalid.
718
+
- **403 Forbidden**: The access token is valid but lacks the required scope.
719
+
- **Subject Mismatch**: The returned `sub` claim does not match the `expectedSubject` (if provided).
Passwordless lets users authenticate with a one-time code (or magic link) delivered by email or SMS, rather than a password. The SDK supports two passwordless approaches:
0 commit comments