-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Update blazor templates with Microsoft.Identity.Web APIs #24268
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
Merged
JunTaoLuo
merged 9 commits into
release/5.0-preview8
from
johluo/identity-web-templates-balzor
Jul 29, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
da83f7c
Update blazor and components web templates
f062623
Update Identity.Web version
52163af
Fix usings
c46d5dc
Updates
be9e124
Formatting feedback
6a10e13
Casing
e6d3cc4
Fix bug in template.json
083e391
More template fixes
d2854d6
Reset baseline tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
37 changes: 37 additions & 0 deletions
37
...ojectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/CallWebApi.razor
This file contains hidden or 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,37 @@ | ||
@page "/callwebapi" | ||
|
||
@using BlazorServerWeb_CSharp | ||
@using Microsoft.Identity.Web | ||
|
||
@inject IDownstreamWebApi downstreamAPI | ||
@inject MicrosoftIdentityConsentAndConditionalAccessHandler ConsentHandler | ||
|
||
<h1>Call an API</h1> | ||
|
||
<p>This component demonstrates fetching data from a Web API.</p> | ||
|
||
@if (apiResult == null) | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
else | ||
{ | ||
<h2>API Result</h2> | ||
@apiResult | ||
} | ||
|
||
@code { | ||
private string apiResult; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
try | ||
{ | ||
apiResult = await downstreamAPI.CallWebApiAsync("me"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
ConsentHandler.HandleException(ex); | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...jectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/ShowProfile.razor
This file contains hidden or 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,84 @@ | ||
@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; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.