-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Teams Toolkit support for Blazor WASM #13180
Comments
👋 Hi @dscheiermann, Thank you for reporting this issue! We want to let you know that: ⏱️ Our team will personally review your issue ✨ This is an AI-generated initial response It sounds like you're experiencing issues with integrating MSAL authentication in a Blazor WebAssembly (WASM) application within Microsoft Teams, specifically when embedding it as a Teams tab. The main problem is the loss of authentication state when using MSAL with popups or redirects within the Teams desktop version. Here's a detailed response addressing your problem and suggesting solutions: Problem Summary:
Proposed Solution:To resolve these issues, you need to combine MSAL and Teams SSO in a way that the authentication state is maintained across your Blazor WASM application. Here are some steps and suggestions:
Example Implementation:Here's an example of how you can create a custom using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.JSInterop;
using System.Security.Claims;
using System.Threading.Tasks;
public class TeamsAuthenticationStateProvider : AuthenticationStateProvider
{
private readonly IJSRuntime _jsRuntime;
public TeamsAuthenticationStateProvider(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
var user = await GetUserFromTeamsSSO();
var identity = user != null
? new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, user) }, "TeamsSSO")
: new ClaimsIdentity();
var userClaimsPrincipal = new ClaimsPrincipal(identity);
return new AuthenticationState(userClaimsPrincipal);
}
private async Task<string> GetUserFromTeamsSSO()
{
// Use JSInterop to call Teams SDK and get the user information
var user = await _jsRuntime.InvokeAsync<string>("microsoftTeams.authentication.getAuthToken");
return user;
}
} Additional Resources:
Alternative Considerations:
By following these steps and implementing a custom For more detailed guidance, you can refer to the GitHub issue related to similar integration challenges.
|
Thank you for bringing this issue to our attention. We will look into it and get back to you shortly. |
Is your feature request related to a problem? Please describe.
I have an already existing Blazor WASM application set up with MSAL.
It uses authorized routes and includes role management based on my azure app registration.
Now it needs to be embedded as a teams tab.
The problem is, MSAL authentication with popup flow or redirect do not work in the teams desktop version.
Using the Teams SSO token, I get an authenticated user, but my AuthenticationStateProvider does not recognize the user as authenticated. Which means, that every user is "anonymous". I have already tried using the microsoftTeams.authentication.authenticate to open a popup which loads the authentication page used for MSAL. But it only authenticates the user in the popup and when it closes, the authentication state is lost.
Describe the solution you'd like
I need some sort of way or idea to combine MSAL and Teams SSO to work with authenticated routes and role management
Maybe MSAL is the wrong approach for this kind of solution?
Describe alternatives you've considered
I have switched to Blazor Server and used an internal API for Cookie authentication to make it work. I dont really like this approach, since im moving from webassembly to server.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: