Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/Accounts/Accounts/CommonModule/ContextAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,35 @@ public object GetParameterValue(string resourceId, string moduleName, Invocation
internal async Task<HttpResponseMessage> AuthenticationHelper(IAzureContext context, string endpointResourceIdKey, string endpointSuffixKey, HttpRequestMessage request, CancellationToken cancelToken, Action cancelAction, SignalDelegate signal, NextDelegate next, TokenAudienceConverterDelegate tokenAudienceConverter = null)
{
IAccessToken accessToken = await AuthorizeRequest(context, request, cancelToken, endpointResourceIdKey, endpointSuffixKey, tokenAudienceConverter);
var newRequest = await request.CloneWithContentAndDispose(request.RequestUri, request.Method);
var response = await next(request, cancelToken, cancelAction, signal);

if (response.MatchClaimsChallengePattern())
using (var newRequest = await request.CloneWithContent(request.RequestUri, request.Method))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using (var newRequest = await request.CloneWithContent(request.RequestUri, request.Method))
using (var newRequest = await request.CloneWithContent(request.RequestUri, request.Method))
using (var response = await next(request, cancelToken, cancelAction, signal))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to the implementation of pipeline, the original request and response will be disposed finally.

{
//get token again with claims challenge
if (accessToken is IClaimsChallengeProcessor processor)
var response = await next(request, cancelToken, cancelAction, signal);

if (response.MatchClaimsChallengePattern())
{
try
//get token again with claims challenge
if (accessToken is IClaimsChallengeProcessor processor)
{
var claimsChallenge = ClaimsChallengeUtilities.GetClaimsChallenge(response);
if (!string.IsNullOrEmpty(claimsChallenge))
try
{
await processor.OnClaimsChallenageAsync(newRequest, claimsChallenge, cancelToken).ConfigureAwait(false);
response = await next(newRequest, cancelToken, cancelAction, signal);
var claimsChallenge = ClaimsChallengeUtilities.GetClaimsChallenge(response);
if (!string.IsNullOrEmpty(claimsChallenge))
{
await processor.OnClaimsChallenageAsync(newRequest, claimsChallenge, cancelToken).ConfigureAwait(false);
using (var previousReponse = response)
{
response = await next(newRequest, cancelToken, cancelAction, signal);
}
}
}
catch (AuthenticationFailedException e)
{
throw e.WithAdditionalMessage(response?.GetWwwAuthenticateMessage());
}
}
catch (AuthenticationFailedException e)
{
throw e.WithAdditionalMessage(response?.GetWwwAuthenticateMessage());
}
}
return response;
}
return response;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion tools/Test/SmokeTest/RmCoreSmokeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $resourceTestCommands = @(
@{Name = "Az.StorageSync"; Command = {Get-AzStorageSyncService -ErrorAction Stop}},
@{Name = "Az.Support"; Command = {Get-AzSupportTicket -ErrorAction Stop}},
@{Name = "Az.Resources [Tags]"; Command = {Get-AzTag -ErrorAction Stop}},
@{Name = "Az.Resources [MSGraph]"; Command = {Get-AzAdGroup -First 1 -ErrorAction Stop}},
#@{Name = "Az.Resources [MSGraph]"; Command = {Get-AzAdGroup -First 1 -ErrorAction Stop}},
@{Name = "Az.TrafficManager"; Command = {Get-AzTrafficManagerProfile -ErrorAction Stop}},
@{Name = "Az.Billing [UsageAggregates]"; Command = {Get-UsageAggregates -ReportedStartTime '1/1/2018' -ReportedEndTime '1/2/2018' -ErrorAction Stop}},
@{Name = "Az.Websites"; Command = {Get-AzWebApp -ErrorAction Stop}}
Expand Down