Skip to content

Commit

Permalink
Merge pull request #1686 from dotnet/dev/zahalzel/api_code_update
Browse files Browse the repository at this point in the history
Update Web API code modifier config
  • Loading branch information
zahalzel authored Nov 3, 2021
2 parents 1ea5115 + a9196e2 commit 696717d
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
{
"Block":"Authorize",
"Options": []
},
{
"Block": "RequiredScope(RequiredScopesConfigurationKey = \"AzureAd:Scopes\")",
"Options": []
}
],
"ClassProperties": [
Expand All @@ -140,6 +144,35 @@
}
]
},
"WeatherForecastController": {
"Parameters": [ "ILogger<WeatherForecastController>" ],
"AddParameters" : [
{
"Block":"GraphServiceClient graphServiceClient",
"Options": [ "MicrosoftGraph"]
},
{
"Block":"IDownstreamWebApi downstreamWebApi",
"Options": [ "DownstreamApi"]
}
],
"CodeChanges": [
{
"Block": "_graphServiceClient = graphServiceClient;",
"Options": [ "MicrosoftGraph" ],
"CodeFormatting": {
"NumberOfSpaces": 12
}
},
{
"Block": "_downstreamWebApi = downstreamWebApi;",
"Options": [ "DownstreamApi" ],
"CodeFormatting": {
"NumberOfSpaces": 12
}
}
]
},
"Get": {
"Parameters": [ "IEnumerable<WeatherForecast>" ],
"EditType": {
Expand All @@ -155,6 +188,22 @@
},
"Options": [ "MicrosoftGraph" ]
},
{
"Append": true,
"Block" : "using var response = await _downstreamWebApi.CallWebApiForUserAsync(\"DownstreamApi\").ConfigureAwait(false);",
"CodeFormatting": {
"NumberOfSpaces": 12
},
"Options" : [ "DownstreamApi"]
},
{
"InsertAfter": "await _downstreamWebApi.CallWebApiForUserAsync",
"Block": "\n\n if (response.StatusCode == System.Net.HttpStatusCode.OK)\n {\n var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);\n // Do something\n }\n else\n {\n var error = await response.Content.ReadAsStringAsync().ConfigureAwait(false);\n throw new HttpRequestException($\"Invalid status code in the HttpResponseMessage: {response.StatusCode}: {error}\");\n }",
"CodeFormatting": {
"NumberOfSpaces": 12
},
"Options": [ "DownstreamApi" ]
},
{
"Append": true,
"Block": "HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);",
Expand All @@ -166,6 +215,16 @@
"Usings": [
"Microsoft.AspNetCore.Authorization",
"Microsoft.Identity.Web.Resource"
],
"UsingsWithOptions": [
{
"Block": "Microsoft.Graph",
"Options": [ "MicrosoftGraph" ]
},
{
"Block": "Microsoft.Identity.Web",
"Options": [ "DownstreamApi" ]
}
]
}
]
Expand Down

0 comments on commit 696717d

Please sign in to comment.