Security

Using the ADFS userinfo endpoint instead of allatclaims

This post shows how to keep the ADFS ID token small and fetch extra claims from the OpenID Connect userinfo endpoint instead of using allatclaims. It covers the urn:microsoft:userinfo claim rules and the ASP.NET Core OpenIdConnect setting that merges those claims. It also flags the audience error that appears when the wrong token is sent.

Published
Reading time
3 min read
agent run #6
agent run #6
Go to original bartwullems.blogspot.com

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Key points

  • The userinfo endpoint lives at https://<adfs-server>/adfs/userinfo and is listed in the discovery document.
  • Without an explicit resource, ADFS issues tokens for urn:microsoft:userinfo, so allatclaims is not needed.
  • The claims returned are controlled by issuance transform rules on the urn:microsoft:userinfo resource.
  • In ASP.NET Core, set GetClaimsFromUserInfoEndpoint = true to merge userinfo claims into the principal.
  • Custom claims need a mapping such as ClaimActions.MapJsonKey in addition to that setting.
  • A token issued for your API fails with MSIS9921 on userinfo; request a separate token and do not forward the userinfo token.

The allatclaims scope puts every claim into the ID token, which works until group memberships pile up and the token grows with every request. The userinfo endpoint offers a lighter route: the ID token stays small, and the application fetches extra claims on demand by sending an access token as a bearer. In ADFS the endpoint is tied to the urn:microsoft:userinfo resource, and the claim rules defined on that resource decide what comes back.

In ASP.NET Core, enabling GetClaimsFromUserInfoEndpoint in the OpenID Connect handler does the request for you, and custom claims need an explicit mapping. The main pitfall is audience: userinfo only accepts tokens issued for its own resource, so a token requested for your Web API will be rejected with MSIS9921. Keep the userinfo token in the web app and request a separate token for API calls, never forwarding the userinfo token to the API.

Real-world use

  • An enterprise ASP.NET Core web app with many AD group memberships that wants a smaller ID token.
  • A portal that loads department or manager attributes only on pages that need them.
  • A web front end calling a separate Web API, where each needs its own correctly scoped access token.

Why it matters

.NET teams on ADFS can shrink their ID tokens by moving extra claims to userinfo, but must keep the userinfo and API tokens separate to avoid audience errors.

This summary was generated by the agent from the original post on Bart Wullems (The Art of Simplicity). The full text and all rights belong to its author and publisher. Go to original

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message