-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add web app MVC code modifier * MVC code modifier updates * remove debugger * Revert tests * Bump version to 2.0.2
- Loading branch information
Showing
11 changed files
with
447 additions
and
13 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...ng/Microsoft.DotNet.MSIdentity/CodeReaderWriter/CodeFiles/WebApp/_LoginPartial.cshtml.txt
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,17 @@ | ||
@using System.Security.Principal | ||
|
||
<ul class="navbar-nav"> | ||
@if (User.Identity?.IsAuthenticated == true) | ||
{ | ||
<span class="navbar-text text-dark">Hello @User.Identity?.Name!</span> | ||
<li class="nav-item"> | ||
<a class="nav-link text-dark" asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="SignOut">Sign out</a> | ||
</li> | ||
} | ||
else | ||
{ | ||
<li class="nav-item"> | ||
<a class="nav-link text-dark" asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="SignIn">Sign in</a> | ||
</li> | ||
} | ||
</ul> |
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
317 changes: 317 additions & 0 deletions
317
...icrosoft.DotNet.MSIdentity/CodeReaderWriter/CodeModifierConfigs/cm_dotnet_webapp_mvc.json
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,317 @@ | ||
{ | ||
"Identifier": "dotnet-webapp-mvc", | ||
"Files": [ | ||
{ | ||
"FileName": "Program.cs", | ||
"Options": [ | ||
"MinimalApp" | ||
], | ||
"Methods": { | ||
"Global": { | ||
"CodeChanges": [ | ||
{ | ||
"Block": "WebApplication.CreateBuilder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)", | ||
"InsertBefore": [ | ||
"WebApplication.CreateBuilder.Services.AddControllersWithViews" | ||
], | ||
"LeadingTrivia": { | ||
"Newline": true | ||
} | ||
}, | ||
{ | ||
"Block": "var initialScopes = WebApplication.CreateBuilder.Configuration[\"DownstreamApi:Scopes\"]?.Split(' ') ?? WebApplication.CreateBuilder.Configuration[\"MicrosoftGraph:Scopes\"]?.Split(' ')", | ||
"Options": [ | ||
"DownstreamApi", | ||
"MicrosoftGraph" | ||
], | ||
"InsertBefore": [ | ||
"WebApplication.CreateBuilder.Services.AddAuthentication" | ||
], | ||
"LeadingTrivia": { | ||
"Newline": true | ||
} | ||
}, | ||
{ | ||
"Block": "AddMicrosoftIdentityWebApp(builder.Configuration.GetSection(\"AzureAd\"))", | ||
"Parent": "WebApplication.CreateBuilder.Services.AddAuthentication", | ||
"CodeChangeType": "MemberAccess", | ||
"LeadingTrivia": { | ||
"Newline": true, | ||
"NumberOfSpaces": 4 | ||
} | ||
}, | ||
{ | ||
"MultiLineBlock": [ | ||
"var policy = new AuthorizationPolicyBuilder()", | ||
"\t.RequireAuthenticatedUser()", | ||
"\t.Build()" | ||
], | ||
"Parent": "WebApplication.CreateBuilder.Services.AddControllersWithViews", | ||
"CodeChangeType": "Lambda", | ||
"Parameter": "options", | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 4, | ||
"Newline": true | ||
} | ||
}, | ||
{ | ||
"Block": "options.Filters.Add(new AuthorizeFilter(policy))", | ||
"Parent": "WebApplication.CreateBuilder.Services.AddControllersWithViews", | ||
"CodeChangeType": "Lambda", | ||
"Parameter": "options", | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 4 | ||
} | ||
}, | ||
{ | ||
"Block": "EnableTokenAcquisitionToCallDownstreamApi(initialScopes)", | ||
"Parent": "AddMicrosoftIdentityWebApp", | ||
"CodeChangeType": "MemberAccess", | ||
"Options": [ | ||
"MicrosoftGraph", | ||
"DownstreamApi" | ||
], | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 8, | ||
"Newline": true | ||
} | ||
}, | ||
{ | ||
"MultiLineBlock": [ | ||
"AddMicrosoftGraph(builder.Configuration.GetSection(\"MicrosoftGraph\"))", | ||
" .AddInMemoryTokenCaches()" | ||
], | ||
"Parent": "EnableTokenAcquisitionToCallDownstreamApi", | ||
"CodeChangeType": "MemberAccess", | ||
"Options": [ | ||
"MicrosoftGraph" | ||
], | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 12, | ||
"Newline": true | ||
} | ||
}, | ||
{ | ||
"MultiLineBlock": [ | ||
"AddDownstreamWebApi(\"DownstreamApi\",builder.Configuration.GetSection(\"DownstreamApi\"))", | ||
" .AddInMemoryTokenCaches()" | ||
], | ||
"Parent": "EnableTokenAcquisitionToCallDownstreamApi", | ||
"CodeChangeType": "MemberAccess", | ||
"Options": [ | ||
"DownstreamApi" | ||
], | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 12, | ||
"Newline": true | ||
} | ||
}, | ||
{ | ||
"Block": "WebApplication.CreateBuilder.Services.AddRazorPages()", | ||
"InsertAfter": "WebApplication.CreateBuilder.Services.AddControllersWithViews" | ||
}, | ||
{ | ||
"Parent": "WebApplication.CreateBuilder.Services.AddRazorPages", | ||
"CodeChangeType": "MemberAccess", | ||
"Block": "AddMicrosoftIdentityUI()", | ||
"LeadingTrivia": { | ||
"Newline": true, | ||
"NumberOfSpaces": 4 | ||
} | ||
}, | ||
{ | ||
"InsertAfter": "app.MapControllerRoute", | ||
"Block": "app.MapRazorPages()" | ||
} | ||
] | ||
} | ||
}, | ||
"Usings": [ | ||
"Microsoft.AspNetCore.Authentication", | ||
"Microsoft.AspNetCore.Authentication.OpenIdConnect", | ||
"Microsoft.AspNetCore.Authorization", | ||
"Microsoft.AspNetCore.Mvc.Authorization", | ||
"Microsoft.Identity.Web", | ||
"Microsoft.Identity.Web.UI" | ||
] | ||
}, | ||
{ | ||
"FileName": "_Layout.cshtml", | ||
"Methods": { | ||
"Global": { | ||
"CodeChanges": [ | ||
{ | ||
"MultiLineBlock": [ | ||
"</ul>", | ||
" <partial name=\"_LoginPartial\" />", | ||
" </div>" | ||
], | ||
"ReplaceSnippet": [ | ||
"</ul>", | ||
" </div>" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"FileName": "LoginPartial.cshtml", | ||
"AddFilePath": "Views/Shared/_LoginPartial.cshtml" | ||
}, | ||
{ | ||
"FileName": "HomeController.cs", | ||
"ClassAttributes": [ | ||
{ | ||
"Block": "Authorize" | ||
} | ||
], | ||
"ClassProperties": [ | ||
{ | ||
"Block": "private readonly GraphServiceClient _graphServiceClient", | ||
"Options": [ | ||
"MicrosoftGraph" | ||
] | ||
}, | ||
{ | ||
"Block": "private readonly IDownstreamWebApi _downstreamWebApi", | ||
"Options": [ | ||
"DownstreamApi" | ||
] | ||
} | ||
], | ||
"Methods": { | ||
"HomeController": { | ||
"Parameters": [ | ||
"ILogger<HomeController>" | ||
], | ||
"AddParameters": [ | ||
{ | ||
"Block": "GraphServiceClient graphServiceClient", | ||
"Options": [ | ||
"MicrosoftGraph" | ||
] | ||
}, | ||
{ | ||
"Block": "IDownstreamWebApi downstreamWebApi", | ||
"Options": [ | ||
"DownstreamApi" | ||
] | ||
} | ||
], | ||
"CodeChanges": [ | ||
{ | ||
"Block": "_graphServiceClient = graphServiceClient;", | ||
"Options": [ | ||
"MicrosoftGraph" | ||
], | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 12 | ||
} | ||
}, | ||
{ | ||
"Block": "_downstreamWebApi = downstreamWebApi;", | ||
"Options": [ | ||
"DownstreamApi" | ||
], | ||
"LeadingTrivia": { | ||
"NumberOfSpaces": 12 | ||
} | ||
} | ||
] | ||
}, | ||
"Index": { | ||
"EditType" : { | ||
"Block": "async Task<IActionResult>", | ||
"Options": ["MicrosoftGraph", "DownstreamApi"] | ||
}, | ||
"Attributes": [ | ||
{ | ||
"Block": "AuthorizeForScopes(ScopeKeySection = \"DownstreamApi:Scopes\")", | ||
"Options": [ | ||
"DownstreamApi" | ||
] | ||
}, | ||
{ | ||
"Block": "AuthorizeForScopes(ScopeKeySection = \"MicrosoftGraph:Scopes\")", | ||
"Options": [ | ||
"MicrosoftGraph" | ||
] | ||
} | ||
], | ||
"CodeChanges": [ | ||
{ | ||
"Options": [ "MicrosoftGraph" ], | ||
"Block": " ViewData[\"GraphApiResult\"] = user.DisplayName", | ||
"Prepend": true, | ||
"NumberOfSpaces": 12 | ||
}, | ||
{ | ||
"Options": [ "MicrosoftGraph" ], | ||
"Block": " var user = await _graphServiceClient.Me.Request().GetAsync()", | ||
"Prepend": true, | ||
"NumberOfSpaces": 12 | ||
}, | ||
{ | ||
"Options": [ "DownstreamApi" ], | ||
"Block": " if (response.StatusCode == System.Net.HttpStatusCode.OK)\r\n {\r\n var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);\r\n ViewData[\"ApiResult\"] = apiResult;\r\n }\r\n else\r\n {\r\n var error = await response.Content.ReadAsStringAsync().ConfigureAwait(false);\r\n throw new HttpRequestException($\"Invalid status code in the HttpResponseMessage: {response.StatusCode}: {error}\");\r\n }\r\n", | ||
"Prepend": true, | ||
"NumberOfSpaces": 12 | ||
}, | ||
{ | ||
"Options": [ "DownstreamApi" ], | ||
"Block": " using var response = await _downstreamWebApi.CallWebApiForUserAsync(\"DownstreamApi\").ConfigureAwait(false)", | ||
"Prepend": true, | ||
"NumberOfSpaces": 12 | ||
} | ||
] | ||
}, | ||
"Error": { | ||
"Attributes": [ | ||
{ | ||
"Block": "AllowAnonymous" | ||
} | ||
] | ||
} | ||
}, | ||
"Usings": [ | ||
"Microsoft.AspNetCore.Authorization" | ||
], | ||
"UsingsWithOptions": [ | ||
{ | ||
"Block": "Microsoft.Graph", | ||
"Options": [ "MicrosoftGraph" ] | ||
}, | ||
{ | ||
"Block": "Microsoft.Identity.Web", | ||
"Options": ["DownstreamApi", "MicrosoftGraph"] | ||
} | ||
] | ||
}, | ||
{ | ||
"FileName": "Index.cshtml", | ||
"Options": [ | ||
"MicrosoftGraph", | ||
"DownstreamApi" | ||
], | ||
"Methods": { | ||
"Global": { | ||
"CodeChanges": [ | ||
{ | ||
"Block": "\n<div>API result</div>\n<div>@ViewData[\"ApiResult\"]</div>\n", | ||
"Options": [ | ||
"DownstreamApi" | ||
] | ||
}, | ||
{ | ||
"Block": "\n<div>Graph API result</div>\n<div>@ViewData[\"GraphApiResult\"]</div>\n", | ||
"Options": [ | ||
"MicrosoftGraph" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
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.