@using System.IO
@using Azure.Core
@using Microsoft.Graph
@using Microsoft.Graph.Models
@inject TeamsFx teamsfx
@inject TeamsUserCredential teamsUserCredential
Get the user's profile
@if (NeedConsent)
{
Click below to authorize this app to read your profile photo using Microsoft Graph.
Authorize
}
else if (!string.IsNullOrEmpty(@ErrorMessage))
{
@ErrorMessage
}
else if (Profile != null)
{
Hello @Profile.DisplayName
}
@code {
[Parameter]
public string ErrorMessage { get; set; }
public bool IsLoading { get; set; }
public bool NeedConsent { get; set; }
public User Profile { get; set; }
private readonly string _scope = "User.Read";
protected override async Task OnInitializedAsync()
{
IsLoading = true;
if (await HasPermission(_scope))
{
await ShowProfile();
}
}
private async Task ShowProfile()
{
IsLoading = true;
var graph = GetGraphServiceClient();
Profile = await graph.Me.GetAsync();
IsLoading = false;
ErrorMessage = string.Empty;
}
private async Task ConsentAndShow()
{
try
{
await teamsUserCredential.LoginAsync(_scope);
NeedConsent = false;
await ShowProfile();
}
catch (ExceptionWithCode e)
{
ErrorMessage = e.Message;
}
}
private async Task