Forum Discussion

ade_2910's avatar
ade_2910
Copper Contributor
Nov 27, 2023

Problems with developing blazor teams tab app using teams tools kit

I'm following the tutorial here to deploy teams app using the teams toolkit
https://learn.microsoft.com/en-us/microsoftteams/platform/toolkit/toolkit-v4/create-new-project-vs?pivots=visual-studio-v17-7

I'm currently having problems using the graph of the signed in user, I get the error 

{"Failed to get access token from OAuth identity server, please login(consent) first"}

I'm unable to acquire an access token from the OAuth identity server to make Microsoft Graph API calls, despite the user being authenticated successfully. The specific error message is: "Failed to get access token from OAuth identity server, please login(consent) first", which occurs even after the user has logged in and consented to the required permissions.

To Reproduce Steps to reproduce the behavior:

  1. User logs in successfully using TeamsUserCredential.
  2. Attempts to call Microsoft Graph API (e.g., graph.Me.Events.GetAsync()).
  3. Receives an error indicating that the access token is not available, suggesting a consent/login issue.
  4. This occurs despite ensuring the user has authenticated and consented to the necessary scopes.

Expected behavior After successful user login and consent, the app should be able to acquire an access token and make calls to the Microsoft Graph API without encountering the mentioned error.

Screenshots (Attach any relevant screenshots that might help to understand the issue better.)

Additional context The GetUserInfoAsync() call works as expected, confirming that the user is authenticated. However, subsequent calls to Microsoft Graph API fail due to the access token issue. The required Microsoft Graph permissions have been configured in the app registration in Azure AD, and admin consent has been granted where necessary.

This issue seems to be a blocker for accessing the Microsoft Graph API despite following the authentication and consent flow as outlined in the TeamsFx documentation.


here's the code snippet

try
{
IsLoading = true;

var user = await teamsUserCredential.GetUserInfoAsync();
await teamsUserCredential.GetTokenAsync(new TokenRequestContext(_scopes), new System.Threading.CancellationToken());
var graph = GetGraphServiceClient();
var test = await graph.Me.Events.GetAsync();

Profile = await graph.Me.GetAsync();
UserPhotoUri = await GetPhotoAsync(graph);
}
catch(Exception ex)
{
throw ex;
}

this code is called after this 

await teamsUserCredential.LoginAsync(_scopes);

anyone got any idea of what is going on?

No RepliesBe the first to reply

Resources