Skip to content

Commit

Permalink
Jmprieur/final templates cleanup (#356)
Browse files Browse the repository at this point in the history
* Resynchronizing the templates from ASP.NET Core and fixing issues discovered while testing:
- Client secrets/certificates sections need to be generated when GenerateApiOrGraph
- Replacing the post actions to install the MicrosoftGraph SDK by a conditional package reference in projects
- Removing unsued usings

* Ensuring that client secrets/certificates settings are available when needed

* Adressing Barry's feedback (comments)
  • Loading branch information
jmprieur authored Jul 23, 2020
1 parent b694b72 commit a141b88
Show file tree
Hide file tree
Showing 24 changed files with 317 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"Shared/LoginDisplay.WindowsAuth.razor"
]
},
{
{
"condition": "(IndividualB2CAuth)",
"rename": {
"Shared/LoginDisplay.IndividualB2CAuth.razor": "Shared/LoginDisplay.razor"
Expand Down Expand Up @@ -288,7 +288,7 @@
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Whether to exclude launchSettings.json in the generated template."
"description": "Whether to exclude launchSettings.json from the generated template."
},
"HttpPort": {
"type": "parameter",
Expand Down Expand Up @@ -448,19 +448,6 @@
],
"defaultName": "WebApplication",
"postActions": [
{
"condition": "(GenerateGraph)",
"actionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"description": "Adds Microsoft Graph package.",
"manualInstructions": [
],
"args": {
"referenceType": "package",
"reference": "Microsoft.Graph",
"version": "3.8.0"
},
"continueOnError": true
},
{
"condition": "(!skipRestore)",
"description": "Restore NuGet packages required by this project.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.1-preview" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.2.1-preview" />
<!--#if (GenerateGraph) -->
<PackageReference Include="Microsoft.Graph" Version="3.8.0" />
<!--#endif -->
</ItemGroup>
</Project>
19 changes: 12 additions & 7 deletions ProjectTemplates/templates/BlazorServerWeb-CSharp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
// "CallbackPath": "/signin-oidc",
// "Domain": "qualified.domain.name",
// "SignedOutCallbackPath": "/signout/MySignUpSignInPolicyId",
//#if (GenerateApi)
// "ClientSecret": "secret-from-app-registration",
// "ClientCertificates" : [
// ],
//#endif
// "SignUpSignInPolicyId": "MySignUpSignInPolicyId",
// "ResetPasswordPolicyId": "MyResetPasswordPolicyId",
// "EditProfilePolicyId": "MyEditProfilePolicyId"
Expand All @@ -20,13 +25,14 @@
// "TenantId": "22222222-2222-2222-2222-222222222222",
//#endif
// "ClientId": "11111111-1111-1111-11111111111111111",
////#if (GenerateApi)
//#if (GenerateApiOrGraph)
// "ClientSecret": "secret-from-app-registration",
// "ClientCertificates" : [
// ],
////#endif
//#endif
// "CallbackPath": "/signin-oidc"
// },
////#endif
////#if (GenerateApiOrGraph)
// "CalledApi": {
// /*
Expand All @@ -40,16 +46,15 @@
// "CalledApiUrl": "[WebApiUrl]"
// },
////#endif
//#endif
////#if (IndividualLocalAuth)
// "ConnectionStrings": {
////#if (UseLocalDB)
//#if (UseLocalDB)
// "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-BlazorServerWeb-CSharp-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true"
////#else
// "DefaultConnection": "DataSource=app.db"
//#else
// "DefaultConnection": "DataSource=app.db;Cache=Shared"
//#endif
// },
//#endif
////#endif
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"name": "Blazor WebAssembly App",
"defaultName": "WebApplication",
"description": "A project template for creating a Blazor app that runs on WebAssembly and is optionally hosted by an ASP.NET Core app. This template can be used for web apps with rich dynamic user interfaces (UIs).",
"groupIdentity": "Microsoft.Web.Blazor.Wasm",
"groupIdentity": "Microsoft.Web.Blazor2.Wasm",
"precedence": "6002",
"guids": [
"4C26868E-5E7C-458D-82E3-040509D0C71F",
Expand All @@ -19,7 +19,7 @@
"09732173-2cef-46b7-83db-1334bcb079d3", // Tenant ID
"53bc9b9d-9d6a-45d4-8429-2a2761773502" // Client ID
],
"identity": "Microsoft.Web.Blazor.Wasm.CSharp.5.0",
"identity": "Microsoft.Web.Blazor.Wasm2.CSharp.5.0",
"thirdPartyNotices": "https://aka.ms/aspnetcore/5.0-third-party-notices",
"preferNameDirectory": true,
"primaryOutputs": [
Expand Down Expand Up @@ -496,14 +496,14 @@
"GenerateApiOrGraph": {
"type": "computed",
"value": "(GenerateApi || GenerateGraph)"
}
}
},
"tags": {
"language": "C#",
"type": "project"
},
"postActions": [
{
{
"condition": "(!skipRestore && Hosted)",
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public async Task<IEnumerable<WeatherForecast>> Get()
HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);

string downstreamApiResult = await _downstreamWebApi.CallWebApi();
// You can also specify the relative endpoint and the scopes
// downstreamApiResult = await _downstreamWebApi.CallWebApi("me", new string[] {"user.read"});

var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
// "Instance": "https:////aadB2CInstance.b2clogin.com/",
// "ClientId": "11111111-1111-1111-11111111111111111",
// "Domain": "qualified.domain.name",
//#if (GenerateApi)
// "ClientSecret": "secret-from-app-registration",
// "ClientCertificates" : [
// ],
//#endif
// "SignUpSignInPolicyId": "MySignUpSignInPolicyId"
// },
////#elseif (OrganizationalAuth)
Expand All @@ -24,13 +29,14 @@
// "TenantId": "22222222-2222-2222-2222-222222222222",
//#endif
// "ClientId": "11111111-1111-1111-11111111111111111",
////#if (GenerateApi)
//#if (GenerateApiOrGraph)
// "ClientSecret": "secret-from-app-registration",
// "ClientCertificates" : [
// ],
////#endif
//#endif
// "CallbackPath": "/signin-oidc"
// },
////#endif
////#if (GenerateApiOrGraph)
// "CalledApi": {
// /*
Expand All @@ -44,9 +50,6 @@
// "CalledApiUrl": "[WebApiUrl]"
// },
////#endif
//#endif
// },
//#endif
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,27 +360,27 @@
"datatype": "string",
"replaces": "[WebApiUrl]",
"defaultValue" : "https://graph.microsoft.com/v1.0/me",
"description": "URL of the API to call from the web app."
"description": "URL of the API to call from the web app. This option only applies if --auth SingleOrg, --auth MultiOrg or --auth IndividualB2C is specified."
},
"CallsMicrosoftGraph": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Specifies if the web app calls Microsoft Graph."
"description": "Specifies if the web app calls Microsoft Graph. This option only applies if --auth SingleOrg or --auth MultiOrg is specified."
},
"CalledApiScopes": {
"type": "parameter",
"datatype": "string",
"replaces" : "user.read",
"description": "Scopes to request to call the API from the web app."
"description": "Scopes to request to call the API from the web app. This option only applies if --auth SingleOrg, --auth MultiOrg or --auth IndividualB2C is specified."
},
"GenerateApi": {
"type": "computed",
"value": "((IndividualB2CAuth || OrganizationalAuth) && (CalledApiUrl != \"https://graph.microsoft.com/v1.0/me\" || CalledApiScopes != \"user.read\"))"
},
"GenerateGraph": {
"type": "computed",
"value": "((IndividualB2CAuth || OrganizationalAuth) && CallsMicrosoftGraph)"
"value": "(OrganizationalAuth && CallsMicrosoftGraph)"
},
"GenerateApiOrGraph": {
"type": "computed",
Expand All @@ -394,19 +394,6 @@
],
"defaultName": "WebApplication",
"postActions": [
{
"condition": "(GenerateGraph)",
"actionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"description": "Adds Microsoft Graph package.",
"manualInstructions": [
],
"args": {
"referenceType": "package",
"reference": "Microsoft.Graph",
"version": "3.8.0"
},
"continueOnError": true
},
{
"condition": "(!skipRestore)",
"description": "Restore NuGet packages required by this project.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Web" Version="0.2.1-preview" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.2.1-preview" />
<!--#if (GenerateGraph) -->
<PackageReference Include="Microsoft.Graph" Version="3.8.0" />
<!--#endif -->
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.Identity.Web;
using System.Net;
using System.Net.Http;
using Company.WebApplication1;
#endif
#if (GenerateGraph)
using Microsoft.Graph;
Expand Down Expand Up @@ -38,10 +37,6 @@ public IndexModel(ILogger<IndexModel> logger,
public async Task OnGet()
{
ViewData["ApiResult"] = await _downstreamWebApi.CallWebApi();

// You can also specify the relative endpoint and the scopes
// ViewData["ApiResult"] = await _downstreamWebApi.CallWebApi("me",
// new string[] {"user.read"});
}
#elseif (GenerateGraph)
private readonly GraphServiceClient _graphServiceClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class MicrosoftGraphServiceExtensions
/// <param name="initialScopes">Initial scopes.</param>
/// <param name="graphBaseUrl">Base URL for Microsoft graph. This can be
/// changed for instance for applications running in national clouds</param>
public static IServiceCollection AddMicrosoftGraph(this IServiceCollection services,
public static IServiceCollection AddMicrosoftGraph(this IServiceCollection services,
IEnumerable<string> initialScopes,
string graphBaseUrl = "https://graph.microsoft.com/v1.0")
{
Expand All @@ -30,6 +30,7 @@ public static IServiceCollection AddMicrosoftGraph(this IServiceCollection servi
new GraphServiceClient(graphBaseUrl, new TokenAcquisitionCredentialProvider(tokenAquisitionService, initialScopes));
return client;
});

return services;
}
}
Expand Down
21 changes: 13 additions & 8 deletions ProjectTemplates/templates/RazorPagesWeb-CSharp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
// "ClientId": "11111111-1111-1111-11111111111111111",
// "CallbackPath": "/signin-oidc",
// "Domain": "qualified.domain.name",
//#if (GenerateApi)
// "ClientSecret": "secret-from-app-registration",
// "ClientCertificates" : [
// ],
//#endif
// "SignedOutCallbackPath": "/signout/MySignUpSignInPolicyId",
// "SignUpSignInPolicyId": "MySignUpSignInPolicyId",
// "ResetPasswordPolicyId": "MyResetPasswordPolicyId",
Expand All @@ -20,15 +25,16 @@
// "TenantId": "22222222-2222-2222-2222-222222222222",
//#endif
// "ClientId": "11111111-1111-1111-11111111111111111",
////#if (GenerateApi)
//#if (GenerateApiOrGraph)
// "ClientSecret": "secret-from-app-registration",
// "ClientCertificates" : [
// ],
////#endif
//#endif
// "CallbackPath": "/signin-oidc"
// },
////#endif
////#if (GenerateApiOrGraph)
// "CalledApi": {
// "CalledApi": {
// /*
// 'CalledApiScopes' contains space separated scopes of the Web API you want to call. This can be:
// - a scope for a V2 application (for instance api://b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
Expand All @@ -38,18 +44,17 @@
// */
// "CalledApiScopes": "user.read",
// "CalledApiUrl": "[WebApiUrl]"
// },
// },
////#endif
//#endif
////#if (IndividualLocalAuth)
// "ConnectionStrings": {
////#if (UseLocalDB)
//#if (UseLocalDB)
// "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-Company.WebApplication1-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true"
////#else
//#else
// "DefaultConnection": "DataSource=app.db;Cache=Shared"
//#endif
// },
//#endif
////#endif
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
Loading

0 comments on commit a141b88

Please sign in to comment.