I created a new ASP.NET Core 6.0 MVC web application using Visual Studio 2022, and I define it to use Azure AD for authentication, as follows:
Then I was asked to create an owned application, so I created one named "ad" as follows:
Inside my application’s appsetting.json
I have these settings:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "*****",
"TenantId": "***",
"ClientId": "***",
"CallbackPath": "/signin-oidc"
},
....
}
It seems Visual Studio did all the work for us.
But when I checked the "Certificate & Secrets" in the Azure portal for the generated Azure AD APP, I found that there is not anything assigned:
So now we are going to upload a certificate (.crt file), but i have those questions:-
-
Now the above ASP.NET Core MVC web application already have SSL certificate bought from Go-daddy, so can we use this certificate also inside our Azure Active directory App ?
-
Also, after uploading a certificate inside our Azure Active Directory App >> do we need to pass the certificate Thumbprint from our web application ? if the answer is yes, then what i need to do exactly , do we need to modify the Identity platfrom code?
2
Answers
If you used VS to integrate AAD and create resource for you, then the appsettings.json file should look like this. And it’s also OK to add configurations manually.
=============================================================
Firstly, the client secret is used for calling API, for example Ms graph API. Then in this answer, I demonstrate how to integrate Graph API in the APP, then you can get the client secret which is already generated for you.
After finishing all these steps, your project has already set up, going to
Program.cs
you can see code below, and it already read the configurations including the secret.but you still need to go to
appsettings.json
to paste the client secret into"ClientSecret": "Client secret from app-registration. Check user secrets/azure portal.",
. You’d better to comment"ClientCertificates": []
because you are using secret but not certificate.By the way, the client secret can exist several valid secret at the same time, this is designed for avoid app crash because of secret expired. So you can have 2 client secrets, if one of the secret is about to expire, you can create a new one in Azure AD then paste the secret value into your project. This means, for example, you used the Visual Studio to generate the secret, but you didn’t store the secret, you also create another secret manually in Azure portal and use it in your app.
To authenticate against an Azure AD app using a certificate you need an X.509 cert that:
You will have to reach GoDaddy to see if they can issue certificates that follow the aforementioned requirements.
And yes, you will need to pass the certificate thumbprint. Keep in mind this can be used when requesting an access token alone or in tandem with an id token (hybrid flow):
Follows how to configure your ASP.NET application:
appsettings.json
Program.cs
And how to acquire an access token:
For more information take a look to Scenario: A web app that authenticates users and calls web APIs. For a hybrid flow sample take a look at this sample.