Getting hold of the access token in the sign in process to Azure Active Directory

Morten 21 Reputation points
2019-12-02T09:52:50.4+00:00

Hi,

I want to sign in users to their Microsoft account (Work or school account or Outlook.com accounts). I've managed to do this through example code. However, for my project I want to store the access token for later access. The problem is that I don't know where I can find the access token in the code. I have basic knowledge of OAUTH and using GET and POST commands, but no expert in ASP.NET, Razor or the libraries that handles the authentication or sign in process.

I've created a project as follows, which contained example code to sign in users:

Create new project - ASP.NET Core Web Application - Web Application (Model-View-Controller).
Choose .NET Core 2.2.
Authentication - click "change".
Choose "Work or school accounts". Information: For applications that authenticate users with Active Directory, Microsoft Azure Active Directory, or Office 365.
Enter domain name of my Microsoft Azure Active Directory tenant.
Create.

Running this application, it will ask me to log in and to consent that the application can get access to my account. It works as intended.

But is there any place in the code where I can debug and have a look at the access token? I can't even locate the POST command in the project code, which I assume is called behind the scenes to get hold of it.

Thanks.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments

2 answers

Sort by: Oldest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  2. Morten 21 Reputation points
    2019-12-03T16:23:16.803+00:00

    Thanks, I get these errors when I try this (also tried it in .NET Core 3.0):

    The type arguments for method 'OptionsServiceCollectionExtensions.Configure(IServiceCollection, string, Action)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

    If I try to specify the type of the arguments as CookiePolicyOptions, which was default after the project had been created, then I get errors like

    'BinderOptions' does not contain a definition for 'Events' and no accessible extension method 'Events' accepting a first argument of type 'BinderOptions' could be found (are you missing a using directive or an assembly reference?)

    (not only for Events but also for Authority and TokenValidationParameters).

    Am I missing something?

    The original services.Configure block in my Startup.cs file has the type CookiePolicyOptions and no argument like AzureADDefaults.OpenIdScheme.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.