-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Microsoft Graph option for Blazor Server (#1719)
Enable Microsoft Graph option for Blazor Server, add .razor modification functionality
- Loading branch information
Showing
15 changed files
with
619 additions
and
285 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...ng/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeFiles/Blazor/Server/ShowProfile.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@page "/showprofile" | ||
|
||
@using Microsoft.Identity.Web | ||
@using Microsoft.Graph | ||
@inject Microsoft.Graph.GraphServiceClient GraphServiceClient | ||
@inject MicrosoftIdentityConsentAndConditionalAccessHandler ConsentHandler | ||
|
||
<h1>Me</h1> | ||
|
||
<p>This component demonstrates fetching data from a service.</p> | ||
|
||
@if (user == null) | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
else | ||
{ | ||
<table class="table table-striped table-condensed" style="font-family: monospace"> | ||
<tr> | ||
<th>Property</th> | ||
<th>Value</th> | ||
</tr> | ||
<tr> | ||
<td>Name</td> | ||
<td>@user.DisplayName</td> | ||
</tr> | ||
<tr> | ||
<td>Photo</td> | ||
<td> | ||
@{ | ||
if (photo != null) | ||
{ | ||
<img style="margin: 5px 0; width: 150px" src="data:image/jpeg;base64, @photo" /> | ||
} | ||
else | ||
{ | ||
<h3>NO PHOTO</h3> | ||
<p>Check user profile in Azure Active Directory to add a photo.</p> | ||
} | ||
} | ||
</td> | ||
</tr> | ||
</table> | ||
} | ||
|
||
@code { | ||
User user; | ||
string photo; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
try | ||
{ | ||
user = await GraphServiceClient.Me.Request().GetAsync(); | ||
photo = await GetPhoto(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
ConsentHandler.HandleException(ex); | ||
} | ||
} | ||
|
||
protected async Task<string> GetPhoto() | ||
{ | ||
string photo; | ||
|
||
try | ||
{ | ||
using (var photoStream = await GraphServiceClient.Me.Photo.Content.Request().GetAsync()) | ||
{ | ||
byte[] photoByte = ((System.IO.MemoryStream)photoStream).ToArray(); | ||
photo = Convert.ToBase64String(photoByte); | ||
this.StateHasChanged(); | ||
} | ||
|
||
} | ||
catch (Exception) | ||
{ | ||
photo = null; | ||
} | ||
return photo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.