-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Cannot call the OIDC endpoint with access token from the broker #835
Comments
Hello @marbon87 : Just to clarify a couple of things:
After some testing I'm having trouble reproducing your exact issue, my tokens either correctly have that However, my initial thought is that by default we will set the authority to |
Correct.
Correct.
Correct: Both id tokens have the same sub-claim, starting with
I set the authority but get the same error:
|
Can you clarify if you are using the Id Token or the access token? The broker uses Entra's v1 endpoint, and so Id Tokens will be v1, which are somewhat different than the v2 endpoint Id Tokens (which you are using). Access tokens however should be the same, they are determined by the resource (Graph). |
Hi @bgavrilMS , |
Is https://graph.microsoft.com/.default the correct URI for the userinfo endpoint? If i try https://login.microsoftonline.com/tenant-idopenid/userinfo i also get a 400 reponse with WWW-Authenticate-Header:
|
Hi @bgavrilMS , do you have any updates on this? |
The userinfo endpoint is part of the OIDC document, which all IdP are required to publish. You can find Entra's here: https://login.microsoftonline.com/common/.well-known/openid-configuration I can imagine that KeyCloak will try to find the userinfo endpoint by looking at the Let me try this out on a personal tenant... |
@marbon87 - let me see if I understand correctly: who calls the userinfo endpoint ? KeyCloak or your app? I wasn't able to get a token for the user endpoint, Entra keeps giving me a token with Graph scopes. And the user endpoint refuses it - with error error_description="AADSTS9001014: This token was not issued for the UserInfo endpoint. This may have been a token for Graph or another resource." Is this what you are getting? (the error message is part of the 400) |
Keycloak calls the userinfo enpdoint.
Exactly. |
Ah ok, I think I figured it out. Entra has v1 and v2 endpoints. The OIDC document for v2 is here (notice the v2.0 segment) https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration And so the userinfo endpoint is: The userinfo is indeed hosted by Graph, but this is an implementation detail. The key point here is that when you configure federation between KeyCloak and Entra, you must tell KeyCloak to use the v2 endpoints of AAD. So the authority from KeyCloak's perspective is HTH |
Sorry, but this is also not working.
|
How does your token look like? (make sure to hide any PII like name etc) Here's mine from https://jwt.ms |
I sent it to you by email. |
Thanks I got it. I think it's a broker issue. I am able to get a response if I use the browser to authenticate, but I get the Here's my C# code that repros the issue. internal class Program
{
private const string ClientId = "3bee2617-ab99-4ba5-b390-be397057344f";
//private const string TenantId = "839846c0-9cef-4455-9542-0c36d831d026";
private const string TenantId = "organizations";
private static readonly Uri AuthorityUri = new Uri($"https://login.microsoftonline.com/{TenantId}");
private static readonly Uri RedirectUrl = new Uri("http://localhost");
private static readonly string[] Scopes = new[] { "User.Read" };
private static bool s_useBroker = true;
private static async Task Main(string[] args)
{
[DllImport("user32.dll")]
static extern nint GetForegroundWindow();
var brokerOptions = s_useBroker ?
new BrokerOptions(BrokerOptions.OperatingSystems.Windows) :
new BrokerOptions(BrokerOptions.OperatingSystems.None);
var pca = PublicClientApplicationBuilder
.Create(ClientId)
.WithAuthority(AuthorityUri)
.WithRedirectUri(RedirectUrl.ToString())
.WithParentActivityOrWindow(() => GetForegroundWindow())
.WithBroker(brokerOptions)
.Build();
var result = await pca.AcquireTokenInteractive(Scopes)
.WithPrompt(Prompt.SelectAccount)
.ExecuteAsync();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(result.TokenType, result.AccessToken);
var response2 = await client.GetAsync("https://graph.microsoft.com/oidc/userinfo"); // OIDC - fails with broker, works with browser
var stringResponse2 = await response2.Content.ReadAsStringAsync();
Console.Write(stringResponse2);
var response3 = await client.GetAsync("https://graph.microsoft.com/v1.0/me"); // works with broker and with browser
var stringResponse3 = await response3.Content.ReadAsStringAsync();
Console.Write(stringResponse3);
}
} |
That the token from the browser is working is mentioned in my first post. Do you have a dedicated contact or business support for this kind of issue? We are actually paying a lot for MS Entra... |
I'm editing the issue to make it clear, as it's a pretty long thread. |
@marbon87 - can you convince KeyCloack to call |
https://graph.microsoft.com/v1.0/me does not work either because the response is missing, especiall the sub-claim is missing in the response. |
This is a known, recently discovered defect, in eSTS implementation of the protocol used by Windows broker to issue v2 tokens. We don't have a concrete timeline, but the plan is for eSTS to address this next quarter. |
https://graph.microsoft.com/v1.0/me seems to be working now. Is this uri expected to be used for userinfo? |
Library version used
1.16.0
Java version
21
Is this a new or an existing app?
This is a new app or experiment
Summary of the issue
userinfo_endpoint
, which it reads from the OIDC endpoint.OIDC endpoint: https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration
UserInfo endpoint: https://graph.microsoft.com/oidc/userinfo
Scope requested: User.Read
See a simple repo (in C#) in #835 (comment)
Note that I can call
https://graph.microsoft.com/v1.0/me
endpoint with the WAM token.Issue description and reproduction steps
We are using keycloak as an internal idp and want to use the external to internal token exchange feature.
Therefor i acquire a token silently with MSAL4j and post the access token to keycloak. The problem is that keycloak call the MS Graph userinfo-Endpoint but get's the error: "Token must contain sub claim."
When i acquire an access token by calling the following uri in the browser and use the access-token from the redirect, the token exchange is working:
https://login.microsoftonline.com/my-tenant/oauth2/v2.0/authorize?client_id=my-client-id&response_type=token+id_token&redirect_uri=https://localhost&scope=user.read+openid+profile+email&response_mode=fragment&state=12345&nonce=678910
I compared the two access tokens from MSAL4j and in the browser and guess that the problem in the MSAL4j-access token is the missing xms_st.sub-Claim in the access token.
What do i have to configure, to get that scope in the access token from MSAL4j?
Relevant code snippets
Expected behavior
MS Graph API Userinfo-Endpoint should respond with status code 200.
Identity provider
Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)
Regression
No response
Solution and workarounds
No response
The text was updated successfully, but these errors were encountered: