Is there a way to authenticate an ASP.NET Core MVC controller action using an Azure AD token?

Viewed 386

I need to load an ASP.NET Core MVC web app already in production into a tab in Microsoft Teams. The web app authenticates users using Azure AD OpenID Connect and the web app has its own Azure AD app, so I created a new Teams app and a new Azure AD app.

I fetch the access token of the user from the Azure AD created for Teams App using Teams tab SSO. My requirement is to authenticate the user into the .net core web app using the access token obtained from the Teams app silently. Both these Azure AD app are in the same tenant.

1 Answers

It's definitely possible to do this - you can pass the token to any API calls using the Authorization header, as a Bearer token, and then simply validate it in your API. Here's a very rough example, in Node (it's possible to do JWT validation in .Net as well of course): https://github.com/pnp/teams-dev-samples/blob/main/samples/tab-sso/src/nodejs/api-server/server.js#L29

Here is an example of how to send the token to the backend: https://github.com/pnp/teams-dev-samples/blob/main/samples/tab-sso/src/nodejs/src/components/Tab.js#L76

Related