Azure AD Auth with MSAL in Angular and ASP.NET Core API
Learn how to implement Azure AD authentication in your Angular app using MSAL and connect it securely with ASP.NET Core Web API. Step-by-step setup included.
Open a visual studio, Create new project named ” Asp.Net core web application” or name of your choice, example “OauthGoogle”
When we select the template, which has been given in step 1 there is already Identity class added to project, and now we have to create Database and their tables base on that identity class.
Before running the application, we need to apply migrations to our app
Go to Tools >> NuGet Package Manager >> Package Manager Console.
Enter ”Update-Database” and hit enter key . This will create identity tables.
Now run your application will open the below screen.
Note the URL from the browser address bar. In this case, the URL is https://localhost:44360/ We need this URL to configure our Google app which we will be doing in our next step.
Navigate to https://console.developers.google.com and login using your Google account. If you do not have a Google account, you need to create one. You cannot proceed without a Google account.
After clicking on the Create Project button then shown a popup window for Project name, where you can specify the name of the project where you can use the google API.
After that we need to Enable “Google+API” so we can search in search box and click on the highlighted “Google+API”
And Enable this Google+ API.
Once Goolge+API is enabled it will automatically redirect to API home page. From the API Home page Click on the “Create credentials” button on the right side of the page to configure the secrets for your API.
You will see an “Add credentials to your project” fill the following field
Now going to “OAuth consent screen” at the left side on the page and choose the External option and click on the create button
Select the “Credentials” menu from the left site and after that click on the "+Create credentials" on the highlighted in the snapshot and select OAuth Client Id options.
After click on the OAuth enter the “Application name, Authorized Javascript Origins(if required) and Authorized redirect URIs” and click on the Create button
Click on the Create button you can see your “client Id and Client Secret” has been created.
Now go to project and right click on the project and go to Manage User Secrets, Which Create the secrets.json.
A secrets.json file will open put the following code in it
Now open startup.cs file and put the following code into ConfigureServices method
After clicking on the Login, you see Google button and click on this
After that enter you Email account
Once you logged in with Gmail Id then you will successfully authenticate with Google.
Now go to SQL Server Management Studio and let’s check our database Name “OAuthFacebook” and “Tables”.
Now go to “AspNetUserLogins” and execute. We can see the following detail about Google.
Also execute “AspNetUsers” table and see users are login.
That is it!
Learn how to implement Azure AD authentication in your Angular app using MSAL and connect it securely with ASP.NET Core Web API. Step-by-step setup included.
Learn how to integrate Okta authentication in Angular using OAuth 2.0 and OIDC. Step-by-step guide for secure login, token handling, and route protection.angular
Step-by-step guide to implement Google OAuth2 authentication in ASP.NET Core. Secure your app with Google sign-in, token validation, and user claims.
Learn how to implement Facebook OAuth2 login in ASP.NET Core. Step-by-step guide to configure app ID, secret, and secure authentication with user claims.
Learn how to implement JWT authentication using ASP.NET Core backend and Angular 8 frontend. Secure your app with token-based login in this step-by-step guide.
Continue building secure apps with JWT in Angular 8 and ASP.NET Core. Learn about token refresh, role-based access, and protecting Angular routes in Part 2.
Implement secure JWT authentication in .NET MAUI apps. Learn best practices, tips, and examples to protect your mobile & desktop applications.
Get in touch with Prishusoft – your trusted partner for custom software development. Whether you need a powerful web application or a sleek mobile app, our expert team is here to turn your ideas into reality.