question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The ID for the cosmos cache entry is a random string instead of the account identifier when using AquireTokenOnBehalfOf [Bug]

See original GitHub issue

Logs and Network traces Without logs or traces, it is unlikely that the team can investigate your issue. Capturing logs and network traces is described at https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/logging

Which Version of MSAL are you using ? Microsoft.Identity.Client 4.25.0

Platform .Net Framework 4.7.2

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Auth
    • Username Password
    • Device code flow (browserless)
  • Web App
    • Authorization code
    • OBO
  • Daemon App
    • Service to Service calls

Other? - please describe;

This is when adding msal to an existing app. Msal is not in production on the app currently.

Repro

var your = (code) => here;

Expected behavior AcquireTokenSilent successfully retrieves token from the cache.

Actual behavior When using AquireTokenByAuthorisationCode the id of the cosmos cache entry is the account identifier (objectId.tenantId). Then when I call AcquireTokenSilent the token is successfully retrieved from the cache.

However when using AquireTokenOnBehalfOf the id of the cosmos cache entry is (what looks like) a random string e.g. “JwCRE_PxyK4t2A76iuST6W_jewmNE-1epMH8yAXFPMg” or “DpUHeYQg5xT52Tdk62t_shU5m1Lm2BIVkbhQ6EtzucE”. The rest of the cache entry looks correct. Then when I call AcquireTokenSilent, the retrieval fails with “No Refresh Token found in the cache”, which makes sense since it is trying to use the account identifier to retrieve the token from the cache but that account identifier doesnt exist.

Possible Solution

Additional context/ Logs / Screenshots Add any other context about the problem here, such as logs and screebshots.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jmprieurcommented, Mar 3, 2021

In the link you provided it states this, which lead to my confusion:

“The protected web API can also call AcquireTokenSilent later to request tokens for other downstream APIs on behalf of the same user. AcquireTokenSilent refreshes the token when needed.”

I’ve fixed the documentation, @SirElTomato. thanks for the heads-up.

1reaction
SirElTomatocommented, Mar 2, 2021

@jmprieur Thanks for your reply. I’m not sure I understand why that is relevant to my problem though. I’m using an MS caching library (Microsoft.Extensions.Caching.Cosmos) to handle saving and retrieving the tokens and whilst it saves the tokens, it can cannot retrieve them for use later on. Please suggest how I can proceed?

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot delete Cosmos DB Item with Illegal Id
Items already inserted in the container for the ID can be replaced by using RID values instead of name-based references. 142969-image.png.
Read more >
Override id creation in Azure cosmos DB
Is there a way to force cosmos DB to ignore the id field in JSON and create a GUID for each entry, like...
Read more >
Azure Cosmos DB integrated cache - Overview
An item cache for point reads; A query cache for queries. The integrated cache is a read-through, write-through cache with a Least Recently...
Read more >
Acceptable encoding for Cosmos DB IDs to replace illegal ...
I'm trying to store data in Cosmos DB where the IDs use a slash (/). However slash is an illegal character in Cosmos...
Read more >
Preventing Headaches with Cosmos Document IDs
The following simple tip regarding Cosmos DB's document identifier property may help you avoid creating a hard-to-find bug in your code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found