page_type | languages | products | description | urlFragment | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
| This sample demonstrates a React & Redux single-page application authorizing an ASP.NET Core Web API to call MS Graph API on its behalf using the MS Graph SDK | ms-identity-javascript-react-spa-dotnetcore-webapi-obo |
This sample demonstrates a React & Redux single-page application which lets a user authenticate and then obtain an access token to call an ASP.NET Core Web API, protected by Azure AD. The Web API then calls the MS Graph API on the user's behalf using the on-behalf-of flow.
The Web APIs call to MS Graph API is made using the MS Graph SDK.
[!NOTE] This sample is configured to allow sign-ins with personal Microsoft accounts ONLY using the
/consumers
endpoint. If you would like to allow sign-ins with work and school accounts in your tenant, see this note. Learn more about supported account types and validation differences between them.
File/folder | Description |
---|---|
AppCreationScripts |
Contains Powershell scripts to automate app registration. |
ReadmeFiles |
Sample readme files. |
ProfileAPI |
Source code of the ProfileAPI. |
ProfileSPA |
Source code of the ProfileSPA. |
CHANGELOG.md |
List of changes to the sample. |
CONTRIBUTING.md |
Guidelines for contributing to the sample. |
README.md |
This README file. |
LICENSE |
The license for the sample. |
Using a command line interface such as VS Code integrated terminal, follow the steps below:
From your shell or command line:
git clone https://github.com/Azure-Samples/ms-identity-javascript-react-spa-dotnetcore-webapi-obo.git
or download and extract the repository .zip file.
[!NOTE] Given that the name of the sample is quiet long, and so are the names of the referenced NuGet packages, you might want to clone it in a folder close to the root of your hard drive, to avoid the 256 character path length limitation on Windows.
cd ProfileAPI
dotnet restore
dotnet dev-certs https --clean
dotnet dev-certs https --trust
Learn more about HTTPS in .NET Core.
cd ProfileSPA
npm install
There are two projects in this sample. Each needs to be separately registered in your Azure AD tenant. To register these projects, you can:
On Windows, run PowerShell and navigate to the root of the cloned directory
In PowerShell run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
Run the script to create your Azure AD application and configure the code of the sample application accordingly.
In PowerShell run:
cd .\AppCreationScripts\
.\Configure.ps1
Other ways of running the scripts are described in App Creation Scripts The scripts also provide a guide to automated application registration, configuration and removal which can help in your CI/CD scenarios.
ProfileAPI
.app secret
),api://{clientId}
).access_as_user
Access ProfileAPI as a user
Accesses the ProfileAPI Web API as a user
Access ProfileAPI as a user
Accesses the ProfileAPI Web API as a user
ProfileSPA
.http://localhost:3000
.ProfileAPI
API, or the name you entered for the Web APIProfileSPA
and go back to your app registration for ProfileAPI
.
KnownClientApplications
, and add the Application (client) ID of the ProfileSPA
application copied from the Azure portal.
i.e. KnownClientApplications: [ "your-client-id-for-ProfileSPA" ]
In the steps below, "ClientID" is the same as "Application ID" or "AppId".
ProfileAPI\appsettings.json
fileDomain
and replace the existing value with your Azure AD tenant name.ClientId
and replace the existing value with the application ID (clientId) of the ProfileAPI
application copied from the Azure portal.ClientSecret
and replace the existing value with the Client Secret of the ProfileAPI
application copied from the Azure portal.In the steps below, "ClientID" is the same as "Application ID" or "AppId".
ProfileSPA\src\utils\authConfig.js
fileclientId
and replace the existing value with the application ID (clientId) of the ProfileSPA
application copied from the Azure portal.redirectUri
and replace the existing value with the base address of the ProfileSPA project (by default http://localhost:3000/
).resourceUri
and replace the existing value with the base address of the ProfileAPI project (by default https://localhost:44351/api/profile
).resourceScope
and replace the existing value with Scope you created earlier api://{client_id}/.default
.Using a command line interface such as VS Code integrated terminal, locate the application directory. Then:
cd ../
cd ProfileAPI
dotnet run
In a separate console window, execute the following commands
cd ProfileSPA
npm start
http://localhost:3000
.[!NOTE] Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the GitHub Issues page.
To debug the .NET Core Web API that comes with this sample, install the C# extension for Visual Studio Code.
Learn more about using .NET Core with Visual Studio Code.
This sample demonstrates the following Azure AD and Microsoft Identity Platform workflows:
For more information, visit the following links:
Articles about the Microsoft identity platform are at http://aka.ms/aaddevv2, with a focus on:
To lean more about the application registration, visit:
Use Stack Overflow to get support from the community.
Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
Make sure that your questions or comments are tagged with [msal
dotnet
angular
azure-active-directory
].
If you find a bug in the sample, please raise the issue on GitHub Issues.
To provide a recommendation, visit the following User Voice page.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。