Implementing Azure B2C using OpenIdConnect in .Net Core Web App(Model-View-Controller)
Muhammad Arslan Khan
PUCIT | Power Platform | Dynamics 365 | ASP.NET MVC | ASP.NET Core | Dynamics 365 Plugins | SQL | JavaScript
What is Azure Active Directory B2C?
Azure Active Directory B2C provides business-to-customer identity as a service.
Customers can use their preferred social, enterprise, or local account identities to get single sign-on access to your applications and APIs. Azure AD B2C service is used for authorization such as access to API resources by authenticated users. Azure AD B2C is a white-label authentication solution which means it helps to customize the entire user experience with your brand so that it blends seamlessly with your web and mobile applications.
Steps to Implement Azure B2C Authentication
1)Create B2C Tenant
2)Register App
3)Create User Flows
4)Create Asp.Net Core Web App (Model-View-Controller)
Create Tenant
Give name, location of your Tenant and use subscription and resource group
Now Switch to created B2C Tenant
When Tenant is created it give detail about Domain name, subscription ID and Resource Group
Now next step is to register an app and define User Flows
App Registration
Define Name of your app and Redirect URL where Token will be send after successfully authentication
Check Access Token and ID token to received as response of authentication.
Now Create Different User Flows according to your requirements
User flows help quickly enable common identity tasks. User flow help user to interact with application like creating new account ,sign in ,Password reset or edit the profile
Name the user flow and add multifactor authentication through different medium if required
Define attribute that you want to take from user during signup process also claims attributes that you want to sent back as a response to application after sccessful authentication
Azure Tenant provide built in attribute, but we can also define our custom attribute according to requirement
领英推荐
You can also define lifetime of Access & ID Token after creating a user flow
User flow also facilitates to define captcha
You can also add custom HTML ,CSS Page by simply give URL of custom pages after customization
Define different User flows according to requirements
Final Step in to Create a .Net project and connect application to Azure forauthentication process using OpenIDConnect
By using following step it will authomatically define our appsettings and
program.cs file code we do not need to manually add values in appsettings
Sign in with your Azure Account and select your created B2C tenant and
registered App
.Net project will automatically install dependencies like OpenIdConnect
package and other dependencies
Appsettings.Json will contains Tenant ID, ClientID (app id) callback URL
where token as a response will e send and user flows URL
Run application and signup your new account
Azure B2C Tenant save registered users in User section. You can view or delete account of user
Sign in with your credential
After creating new account and successful login Azure B2C will return token
to callback url and display login user name
Claims From Tokens
You can also reset you password by simple click of reset password link
Profile edit