How to manage authentication and authorization in .net core based on the token received from third party rest API? - authentication

I am developing web Application in .Net Core 3. I need to manage authentication and authorization in web app based on the JWT token received from other rest API application. Is it possible to manage role based based page and navigation between them without using/creating the database for web app? How to manage token expiration for web application if we are able to manage that?

You can add same token validation parameters as you have in your other rest API app with same IssuerSigningKey, and use tokens with your main app as well

Related

Authenticating ASP.NET Core Background Service to Azure/Office365 through an Angular SPA using msal-angular

I'm building a web application; the frontend is a SPA using Angular8 and the backend is an ASP.NET Core 3.1 Web API.
The application already has its own authentication scheme, setup using JWT Bearer tokens.
Now I need to add the ability for the backend to sync events on the Office365 calendar of the users. The requirements are:
Users should login to their Microsoft Office365 account on the frontend;
The frontend should "save" the results of the authentication on the backend, allowing the backend to periodically interact with the Micosoft Graph API.
In the (rare) case for some reasons the authentication must be renewed (for example different rights/scopes are required), the backend will notify the frontend that a new login is required.
I am currently able to perform a successful login in example applications using MSAL.NET and msal-angular, but what I cannot do is to pass the result of the authentication I get from msal-angular to .NET and use it to proceed with further calls and token renewals.
I am thinking about modifying/extending the msal-angular library to support the MSALv3 cache serialization scheme used in MSAL.NET and sending the cache to my web app, but it seem a very complicated and fragile (I see the internals of those libs are not stable across versions).
So, is this use case supported in some other way by MSAL? Should I use some different libraries?
You can go through the following docs to see if they are helpful in your scenario.
Acquire and cache tokens using the Microsoft Authentication Library (MSAL).
Single-page application: Acquire a token to call an API
Get a token from the token cache using MSAL.NET
Initialize client applications using MSAL.NET

consuming .net core api by xamarin form application

I'm currently working on a Xamarin form that consumes data from the.net core API.
For API side, I use Abp framework.
By using this reference, I can consume data from API.
But in this example, the user needs to login using an administrator credential.
What I need to do is, I just need to consume data from API without login.
Is it correct way if I add [AllowAnonymous] attribute over the API method that I need to access ?
This is the example they show,
var accessToken = await _loginService.AuthenticateAsync();
var httpClient = GetHttpClient(accessToken);
Is there any example like just using clientId/secrets and without using accessToken?
What I need to do is, I just need to consume data from API without login.
This refers to Server-to-Server authentication; backend making request to an other backend without user interaction.
The authentication flow you are looking for, is named Client Credentials Flow.
It boils down to:
Add your api (abp app) as an api resource and api scope at authentication server.
Add your ui app (xamarin app) as a client at authentication server.
Declare a client secret for your xamarin app at authentication server.
Make an access_token request from xamarin app to authentication server with the api scope and client secret that you have already created above.
Its implementation can be varied on authentication server provider (namely your _loginService). It can be Identityserver4, Microsoft, Google etc etc.
If you are using ABP application backend (as authentication server), it handles most of the automated stuff in the background. You can check abp synchronous communication between microservices docs that has explanation about how client credentials is used between microservices.

How do I Authenticate and get tokens for ASP .NET CORE WEB API Application With On-Premisis ADFS?

I am having a web application which is using ADFS for authentication this application is done in .net framework. I have written services in ASP.NET Core as of now there is no authentication for web api requests i want to to add ADFS authentication to web api how can i access this web api? how do i talk to this api after configuring it to adfs? what is the best way to access web api as they both were ADFS applications
To issue the token for the web API, we need to make the ADFS to aware it by creating a relying party trust for the web API. And when we add a replying party we need to specify the identifiers for the replying party:
And then we can use this identifiers as the reosurce URI to acquire the token for this replying party.
Please ensure that the resource URI is correct as you config.
here is a very nice article about developing with ADFS using OAuth:
https://msdn.microsoft.com/en-us/library/dn633593.aspx
Check this thread too
https://www.scottbrady91.com/Identity-Server/Identity-Server-3-using-WS-Federation
Hope it helps.

Web app ClaimsIdentity in Webapi

I've created a mvc web application that uses openid to authenticate with Azure Ad and get the claims along with the token. I'm interfacing with Web Api to do the business transactions. The web Api is configured to oauth bearer tokens.
I've created separate oauth clients in Azure Ad for the Web App and Web Api. I'm able to get a token for Web Api from the Mvc Controller using AuthenticationContext to send to request to Web Api. I need to know how I can send the current User Claims as well to the Web Api. The claims in the Web Api are not having the claims of the User from the Web App.
Let me provide a bit more context here. I've created a MVC Web Application and a Web Api layer. The MVC Web App is configured to use OpenID authentication using Azure AD and I've configured the Web Api layer to authorize using OAuth Bearer tokens. The actions in the Web Api layer will be called through ajax requests and the bearer token will be added to the header of each Ajax requests. When the User is authenticated in the Web App, additional claims are added to the User on top of the claims from Azure Ad. I'm able to create a token for the Web Api layer using AuthenticationContext.AcquireToken, but the token for Web Api does not have the User info from the Web App.
I'm taking a wild stab in the dark here, based on what I think is happening.
Claims are attached the user, so theoretically, any claim you add in one place should be available in the other, as long as both applications share the same user datastore. However, claims are loaded at the point of authentication and not dynamically updated. As a result, if you're already logged in to the web application and you add a claim with your Web Api, that claim will not be available on the web application side until the user is re-authenticated.

ASP.NET web api authentication with bacbone.js

I'm implementing a RESTful web service using ASP.Net Web Api and Backbone.js at client side. What will the best way to authenticate user?
You are building SPA then it is recommend to use Token Based Authentication not Cookies, once you obtain the access token from the Auth server (Web API) you need to store it in html5 local storage then with each subsequent request to a protected resource you need to send this access token in the "Authorization" header using bearer scheme.
I've compiled detailed post about this but it uses Angular, so it will be very close to backbone.js