- Select File | New Project
- Choose web API
- For Authentication, choose Microsoft identity platform
- Observe the appsettings.jon. We need to configure the project
- Observe the startup.cs (web api), and the controller (Authorize attribute, scope verification)
- Navigate the aka.ms link: https://aka.ms/dotnet-template-ms-identity-platform and learn:
- how to install the tool (dotnet global tool)
- how to install it in Visual Studio as an external tool
Select the project Make sure the appsettings.json is displayed Select Tools | msidentity-app-sync Observe the appsettings.json, the ClientId and TenantId were modified
Run the application from Visual Studio Look at the swagger Try to execute it. 401 unauthenticated; This is normal. It's a protected API
Copy the command in swagger (for instance:"https://localhost:44359/WeatherForecast")
- Open the app registration portal https://portal.azure.com
- In Azure Active Directory | Application registration, find the application
- Look at the Expose an API page, and copy the scopes (for instance: "api://4d36eb86-0d46-4090-9283-c42dc9f149ef/access_as_user")
-
In Visual Studio right click on the solution and Select Open folder in file explorer
-
In File explorer, New Folder, named MyWebApp
-
In File explorer, right click on the new folder and Open a terminal command
-
In the terminal command create the web app by typing
dotnet new webapp --auth SingleOrg --called-api-url
followed by the URL of your web API, and followed by--called-api-scopes
followed by the scopes of your web API. This will be something like this:dotnet new webapp --auth SingleOrg --called-api-url https://localhost:44359/WeatherForecast --called-api-scopes api://4d36eb86-0d46-4090-9283-c42dc9f149ef/access_as_user
-
Still in the console add the new project to the solution using
dotnet sln (add)
:dotnet sln ..\myWebAPI.sln add .\myWebApp.csproj
- Back to visual studio, the solution was modified by adding the web app.
- Observe the appsettings.json. See the client secret.
- and the startup.cs
- and the index.cshtml page which calls the web API.
- Select the web app project
- Run the tool
- Setup the startup project in the solution to start both projects
- Run the solution. The web app signs me in and displays the result of the API.