Skip to content

Commit

Permalink
Servicing release for dotnet-aspnet-codegenerator and dotnet-msidenti…
Browse files Browse the repository at this point in the history
…ty (#1816)

* Code updates for blazor server Downstream API option (#1767)

* Add blazor server, and some code refactors

* updating System package versions due to security vulnerabilities (#1781)

* updating System package versions due to security vulnerabilities

* revert package version for test.

* potential fix?

* fixed all compliance issues.

* clean up

* Refactor ProjectModifier and remove calls to Directory.EnumerateFiles (#1782)

* Removing EnumerateDirectories, other refactors

* Create and Update Blazor Wasm App Registrations (#1793)

* scripts and gitignore

* Update redirect uris

* create and update Blazor Wasm apps

* Process callback paths for remote URIs

* Add comments and refactor for better readability

* String updates

* Fix updating bug, update strings

* Blazor Server: Code updates for Microsoft Graph and Downstream API options (#1798)

Adding code updates for blazor server non-auth templates

* Blazor Wasm: Code Updates and AppSettings updates (#1805)

* Blazor Wasm: Code Updates and AppSettings updates

* App Settings and Code Modification updates

* App Settings and Code Modification updates

* App Settings and Code Modification updates

* App Settings and Code Modification updates

* Update AzureAdProperties logic
Address PR comments
Refactor tests

* Update version to 1.0.2, add reference to Nuget package

* Refactor projectDescriptionReader logic

* Downstream API fixes

* Add AppSettings modification to CodeUpdate option

* not throwing exception on invalid bootstrap versions. (#1814)

* not throwing exception on invalid bootstrap .

* minor fix

* bump up dotnet-aspnet-codegenerator version.

Co-authored-by: zahalzel <75647613+zahalzel@users.noreply.github.com>
  • Loading branch information
deepchoudhery and zahalzel committed Mar 24, 2022
1 parent 9fcc9b9 commit 6eb0436
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 69 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.MSIdentity.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UsingToolNetFrameworkReferenceAssemblies>true</UsingToolNetFrameworkReferenceAssemblies>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.0.1</VersionPrefix>
<VersionPrefix>1.0.2</VersionPrefix>
<PreReleaseVersionLabel>rtm</PreReleaseVersionLabel>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<!--
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- Ref packages -->
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>6.0.1</VersionPrefix>
<VersionPrefix>6.0.2</VersionPrefix>
<PreReleaseVersionLabel>rtm</PreReleaseVersionLabel>
<IsServicingBuild Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</IsServicingBuild>
<!--
Expand Down Expand Up @@ -114,7 +114,7 @@
<XunitRunnerVisualStudioPackageVersion>2.4.2-pre.9</XunitRunnerVisualStudioPackageVersion>
</PropertyGroup>
<PropertyGroup>
<SystemCollectionsImmutableVersion>7.0.0-preview.1.22076.8</SystemCollectionsImmutableVersion>
<SystemCollectionsImmutableVersion>6.0.0</SystemCollectionsImmutableVersion>
<SystemNetHttpVersion>4.3.4</SystemNetHttpVersion>
<SystemPrivateUriVersion>4.3.2</SystemPrivateUriVersion>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"tools": {
"dotnet": "6.0.200"
"dotnet": "6.0.101"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.21552.1"
},
"sdk": {
"version": "6.0.200",
"version": "6.0.101",
"allowPrerelease": true
}
}
2 changes: 1 addition & 1 deletion scripts/install-aspnet-codegenerator.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set VERSION=6.0.1
set VERSION=6.0.2
set DEFAULT_NUPKG_PATH=%userprofile%\.nuget\packages
set SRC_DIR=%cd%
set NUPKG=artifacts/packages/Debug/Shipping/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@page "/callwebapi"

@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 HttpResponseMessage response;
private string apiResult;

protected override async Task OnInitializedAsync()
{
try
{
response = await downstreamAPI.CallWebApiForUserAsync(
"DownstreamApi",
options => options.RelativePath = "");

if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
apiResult = await response.Content.ReadAsStringAsync();
}
else
{
apiResult = "Failed to call the web API";
}
}
catch (Exception ex)
{
ConsentHandler.HandleException(ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<AuthorizeView>
<Authorized>
Hello, @context.User.Identity?.Name!
<a href="MicrosoftIdentity/Account/SignOut">Log out</a>
</Authorized>
<NotAuthorized>
<a href="MicrosoftIdentity/Account/SignIn">Log in</a>
</NotAuthorized>
</AuthorizeView>
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,21 @@ else
<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;
User? user;

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />

@code{
[Parameter] public string? Action { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

@inject NavigationManager Navigation
@inject SignOutSessionStateManager SignOutManager

<AuthorizeView>
<Authorized>
Hello, @context.User.Identity?.Name!
<button class="nav-link btn btn-link" @onclick="BeginLogout">Log out</button>
</Authorized>
<NotAuthorized>
<a href="authentication/login">Log in</a>
</NotAuthorized>
</AuthorizeView>

@code{
private async Task BeginLogout(MouseEventArgs args)
{
await SignOutManager.SetSignOutState();
Navigation.NavigateTo("authentication/logout");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@inject NavigationManager Navigation

@code {
protected override void OnInitialized()
{
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@
"Options": [ "MicrosoftGraph" ]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,59 +121,90 @@ private PropertyInfo? CodeModifierConfigPropertyInfo

return _codeModifierConfigPropertyInfo;
}
else if (fileName.EndsWith(".cs"))

return codeModifierConfig;
}

private CodeModifierConfig? ReadCodeModifierConfigFromFileContent(byte[] fileContent)
{
try
{
await ModifyCsFile(fileName, file, project, options);
string jsonText = Encoding.UTF8.GetString(fileContent);
return JsonSerializer.Deserialize<CodeModifierConfig>(jsonText);
}
catch (Exception e)
{
_consoleLogger.LogMessage($"Error parsing Code Modifier Config for project type { _toolOptions.ProjectType }, exception: { e.Message }");
return null;
}
else if (fileName.EndsWith(".cshtml"))
}

private async Task HandleCodeFileAsync(CodeFile file, CodeAnalysis.Project project, CodeChangeOptions options, string identifier)
{
if (!string.IsNullOrEmpty(file.AddFilePath))
{
await ModifyCshtmlFile(fileName, file, project, options);
AddFile(file, identifier);
}
else if (fileName.EndsWith(".razor"))
else
{
await ModifyRazorFile(fileName, file, project, options);
switch (file.Extension)
{
case "cs":
await ModifyCsFile(file, project, options);
break;
case "cshtml":
await ModifyCshtmlFile(file, project, options);
break;
case "razor":
case "html":
await ApplyTextReplacements(file, project, options);
break;
}
}
}

/// <summary>
/// Determines if specified file exists, and if not then creates the
/// file based on template stored in AppProvisioningTool.Properties
/// and adds file to the project
/// then adds file to the project
/// </summary>
/// <param name="file"></param>
/// <param name="identifier"></param>
/// <exception cref="FormatException"></exception>
private void AddFile(CodeFile file)
private void AddFile(CodeFile file, string identifier)
{
var filePath = Path.Combine(_toolOptions.ProjectPath, file.AddFilePath);
if (File.Exists(filePath))
{
return; // File exists, don't need to create
}

// Resource names for addFiles prefixed with "add" and contain '_' in place of '.'
// fileName: "ShowProfile.razor" -> resourceName: "add_ShowProfile_razor"
var resourceName = file.FileName.Replace('.', '_');
var propertyInfo = AppProvisioningTool.Properties.Where(
p => p.Name.StartsWith("add") && p.Name.EndsWith(resourceName)).FirstOrDefault();
var codeFileString = GetCodeFileString(file, identifier);

var fileDir = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(fileDir))
{
Directory.CreateDirectory(fileDir);
File.WriteAllText(filePath, codeFileString);
}
}

private string GetCodeFileString(CodeFile file, string identifier)
{
var propertyInfo = GetPropertyInfo(file.FileName, identifier);
if (propertyInfo is null)
{
return;
throw new FormatException($"Resource file for {file.FileName} could not be found. ");
}

byte[] content = (propertyInfo.GetValue(null) as byte[])!;
string codeFileString = Encoding.UTF8.GetString(content);
if (string.IsNullOrEmpty(codeFileString))
{
throw new FormatException($"Resource file { propertyInfo.Name } could not be parsed. ");
throw new FormatException($"Resource file for {file.FileName} could not be parsed. ");
}

var fileDir = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(fileDir))
{
Directory.CreateDirectory(fileDir);
File.WriteAllText(filePath, codeFileString);
}
return codeFileString;
}

private CodeModifierConfig? ReadCodeModifierConfigFromFileContent(byte[] fileContent)
Expand Down Expand Up @@ -291,7 +322,6 @@ internal async Task ModifyCsFile(CodeFile file, CodeAnalysis.Project project, Co
documentEditor.ReplaceNode(documentEditor.OriginalRoot, modifiedRoot);
await documentBuilder.WriteToClassFileAsync(fileDoc.FilePath);
}
}

/// <summary>
/// Modifies root if there any applicable changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@
<data name="add_dotnet_blazorwasm_UserProfile_razor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CodeReaderWriter\CodeFiles\Blazor\wasm\UserProfile.razor.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="add_dotnet_blazorwasm_Authentication_razor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CodeReaderWriter\CodeFiles\Blazor\wasm\Authentication.razor;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="add_dotnet_blazorwasm_LoginDisplay_razor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CodeReaderWriter\CodeFiles\Blazor\wasm\LoginDisplay.razor;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="add_dotnet_blazorwasm_RedirectToLogin_razor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CodeReaderWriter\CodeFiles\Blazor\wasm\RedirectToLogin.razor;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="AuthNotEnabled" xml:space="preserve">
<value>Authentication is not enabled yet in this project. An app registration will be created, but the tool does not add the code yet (work in progress).</value>
</data>
Expand Down

0 comments on commit 6eb0436

Please sign in to comment.