Skip to content

Commit 4c7ff9c

Browse files
Merge branch 'sidecar' into kecaruso/python-adapter
2 parents f2920b4 + 59c7a7b commit 4c7ff9c

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

src/Microsoft.Identity.Web.Sidecar/Endpoints/AuthorizationHeaderEndpoint.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.ComponentModel;
45
using System.Net.Mime;
56
using Microsoft.AspNetCore.Http.HttpResults;
67
using Microsoft.AspNetCore.Mvc;
@@ -64,9 +65,11 @@ private static OpenApiOperation ConfigureOpenAPI(OpenApiOperation operation)
6465

6566
private static async Task<Results<Ok<AuthorizationHeaderResult>, ProblemHttpResult>> AuthorizationHeaderAsync(
6667
HttpContext httpContext,
67-
[FromRoute] string apiName,
68+
[Description("The downstream API to acquire an authorization header for.")]
69+
[FromRoute]
70+
string apiName,
6871
[AsParameters] AuthorizationHeaderRequest requestParameters,
69-
BindableDownstreamApiOptions? optionsOverride,
72+
BindableDownstreamApiOptions optionsOverride,
7073
[FromServices] IAuthorizationHeaderProvider headerProvider,
7174
[FromServices] IOptionsMonitor<DownstreamApiOptions> optionsMonitor,
7275
[FromServices] ILogger<Program> logger,
@@ -81,7 +84,7 @@ private static async Task<Results<Ok<AuthorizationHeaderResult>, ProblemHttpResu
8184
statusCode: StatusCodes.Status400BadRequest);
8285
}
8386

84-
if (optionsOverride is not null)
87+
if (optionsOverride.HasAny)
8588
{
8689
options = DownstreamApiOptionsMerger.MergeOptions(options, optionsOverride);
8790
}

src/Microsoft.Identity.Web.Sidecar/Endpoints/DownstreamApiEndpoint.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.ComponentModel;
45
using System.Net.Http.Headers;
56
using System.Net.Mime;
67
using System.Text;
@@ -63,9 +64,11 @@ private static OpenApiOperation ConfigureOpenAPI(OpenApiOperation operation)
6364

6465
private static async Task<Results<Ok<DownstreamApiResult>, ProblemHttpResult>> DownstreamApiAsync(
6566
HttpContext httpContext,
66-
[FromRoute] string apiName,
67+
[Description("The downstream API to call")]
68+
[FromRoute]
69+
string apiName,
6770
[AsParameters] DownstreamApiRequest requestParameters,
68-
BindableDownstreamApiOptions? optionsOverride,
71+
BindableDownstreamApiOptions optionsOverride,
6972
[FromServices] IDownstreamApi downstreamApi,
7073
[FromServices] IOptionsMonitor<DownstreamApiOptions> optionsMonitor,
7174
[FromServices] ILogger<Program> logger,
@@ -80,7 +83,7 @@ private static async Task<Results<Ok<DownstreamApiResult>, ProblemHttpResult>> D
8083
statusCode: StatusCodes.Status400BadRequest);
8184
}
8285

83-
if (optionsOverride is not null)
86+
if (optionsOverride.HasAny)
8487
{
8588
options = DownstreamApiOptionsMerger.MergeOptions(options, optionsOverride);
8689
}

src/Microsoft.Identity.Web.Sidecar/Microsoft.Identity.Web.Sidecar.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
<!-- Trimming + perf (Release only) -->
2626
<PropertyGroup Condition="'$(Configuration)'=='Release'">
27-
<PublishTrimmed>true</PublishTrimmed>
27+
<PublishTrimmed>false</PublishTrimmed>
2828
<TrimMode>partial</TrimMode>
29-
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
29+
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
3030
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
3131
<PublishReadyToRun>true</PublishReadyToRun>
3232
<!-- Optional; enable only if you do not rely on culture-specific globalization -->

src/Microsoft.Identity.Web.Sidecar/Models/AuthorizationHeaderRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.ComponentModel;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Text.Json;
67
using System.Text.Json.Serialization;
@@ -15,8 +16,10 @@ namespace Microsoft.Identity.Web.Sidecar.Models;
1516
public readonly struct AuthorizationHeaderRequest
1617
{
1718
[FromQuery]
19+
[Description("The identity of the agent.")]
1820
public string? AgentIdentity { get; init; }
1921

2022
[FromQuery]
23+
[Description("The username of the agent.")]
2124
public string? AgentUsername { get; init; }
2225
}

src/Microsoft.Identity.Web.Sidecar/Models/BindableDownstreamApiOptions.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ namespace Microsoft.Identity.Web.Sidecar.Models;
1515
/// </summary>
1616
public class BindableDownstreamApiOptions : DownstreamApiOptions, IEndpointParameterMetadataProvider
1717
{
18+
/// <summary>
19+
/// The object needs to be non-nullable for the OpenAPI spec generation.
20+
/// This provides a way to know if any override was actually provided.
21+
/// </summary>
22+
public bool HasAny { get; private set; }
23+
1824
public BindableDownstreamApiOptions()
1925
{
2026
}
@@ -25,14 +31,16 @@ public BindableDownstreamApiOptions()
2531
bool hasAny = ctx.Request.Query.Keys.Any(k =>
2632
k.StartsWith(paramName + ".", StringComparison.OrdinalIgnoreCase));
2733

34+
var result = new BindableDownstreamApiOptions();
35+
2836
if (!hasAny)
2937
{
30-
// No override supplied
31-
return ValueTask.FromResult<BindableDownstreamApiOptions?>(null);
38+
return ValueTask.FromResult<BindableDownstreamApiOptions?>(result);
3239
}
3340

41+
result.HasAny = true;
42+
3443
var query = ctx.Request.Query;
35-
var result = new BindableDownstreamApiOptions();
3644

3745
foreach (var key in query.Keys)
3846
{
@@ -75,7 +83,7 @@ public BindableDownstreamApiOptions()
7583
case "claims":
7684
result.AcquireTokenOptions.Claims = last;
7785
break;
78-
case "CorrelationId" when Guid.TryParse(last, out var corrId):
86+
case "correlationid" when Guid.TryParse(last, out var corrId):
7987
result.AcquireTokenOptions.CorrelationId = corrId;
8088
break;
8189
case "fmipath":
@@ -118,7 +126,7 @@ public BindableDownstreamApiOptions()
118126
return ValueTask.FromResult<BindableDownstreamApiOptions?>(result);
119127
}
120128

121-
// Let ApiExplorer/OpenAPI know this should be treated as coming from query
129+
/// <inheritdoc/>
122130
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder)
123131
{
124132
builder.Metadata.Add(new FromQueryAttribute());

src/Microsoft.Identity.Web.Sidecar/OpenAPI/Microsoft.Identity.Web.Sidecar.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
{
5858
"name": "apiName",
5959
"in": "path",
60+
"description": "The downstream API to acquire an authorization header for.",
6061
"required": true,
6162
"schema": {
6263
"type": "string"
@@ -65,13 +66,15 @@
6566
{
6667
"name": "AgentIdentity",
6768
"in": "query",
69+
"description": "The identity of the agent.",
6870
"schema": {
6971
"type": "string"
7072
}
7173
},
7274
{
7375
"name": "AgentUsername",
7476
"in": "query",
77+
"description": "The username of the agent.",
7578
"schema": {
7679
"type": "string"
7780
}
@@ -244,6 +247,7 @@
244247
{
245248
"name": "apiName",
246249
"in": "path",
250+
"description": "The downstream API to acquire an authorization header for.",
247251
"required": true,
248252
"schema": {
249253
"type": "string"
@@ -252,13 +256,15 @@
252256
{
253257
"name": "AgentIdentity",
254258
"in": "query",
259+
"description": "The identity of the agent.",
255260
"schema": {
256261
"type": "string"
257262
}
258263
},
259264
{
260265
"name": "AgentUsername",
261266
"in": "query",
267+
"description": "The username of the agent.",
262268
"schema": {
263269
"type": "string"
264270
}
@@ -431,6 +437,7 @@
431437
{
432438
"name": "apiName",
433439
"in": "path",
440+
"description": "The downstream API to call",
434441
"required": true,
435442
"schema": {
436443
"type": "string"
@@ -618,6 +625,7 @@
618625
{
619626
"name": "apiName",
620627
"in": "path",
628+
"description": "The downstream API to call",
621629
"required": true,
622630
"schema": {
623631
"type": "string"

0 commit comments

Comments
 (0)