locked
Azure AD Token - Client Credential RRS feed

  • Question

  • Hi Team,

    using Microsoft.IdentityModel.Clients.ActiveDirectory;

    I am acquiring Access Token using following code.

                AuthenticationContext authContext = new AuthenticationContext("url");
                ClientCredential cc = new ClientCredential("clientid", "clientcredential");  
                AuthenticationResult result = authContext.AcquireTokenAsync("url", cc).Result;

    The problem is I am getting the same token with 1 hour expiry every time I am calling.

    How can I get new token everytime?

    Please advice.

    Wednesday, June 24, 2020 11:15 PM

Answers

  • Maybe you should create a new TokenCache and use another constructor of AuthenticationContext.

    • Marked as answer by Paul AZ Thursday, June 25, 2020 3:37 PM
    Thursday, June 25, 2020 4:06 AM

All replies

  • Maybe you should create a new TokenCache and use another constructor of AuthenticationContext.

    • Marked as answer by Paul AZ Thursday, June 25, 2020 3:37 PM
    Thursday, June 25, 2020 4:06 AM
  • Hi Paul,

    Thank you for posting here.

    Since this thread is related to Azure AD, I suggest that you can post in Microsoft Q&A forum.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 25, 2020 7:27 AM
  • Why? It is inefficient to create a new token if the user still has a valid OAuth token that hasn't remotely expired. The server is fully within its right to cache and return the same token until it is ready to generate a new one. Creating a token is expensive since it requires retrieving and encoding the claims so avoiding this if a token is still valid makes sense. How Azure does it is documented as part of TokenCache. You can read this for more information and perhaps how to "disable" it.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, June 25, 2020 2:22 PM
  • Thank you.  It worked.
    Thursday, June 25, 2020 3:37 PM