Skip to content

Commit

Permalink
fix interface breaking change (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyf19 authored May 24, 2021
1 parent 37e8c39 commit 222e76a
Show file tree
Hide file tree
Showing 16 changed files with 2,918 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task AuthenticateRequestAsync(HttpRequestMessage request)
string token;
if (appOnly)
{
token = await _tokenAcquisition.GetAccessTokenForAppAsync(Constants.DefaultGraphScope, tenant, authenticationScheme: scheme).ConfigureAwait(false);
token = await _tokenAcquisition.GetAccessTokenForAppAsync(Constants.DefaultGraphScope, authenticationScheme: scheme, tenant: tenant).ConfigureAwait(false);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ private IConfidentialClientApplication GetOrCreateApplication()
/// <inheritdoc/>
public async Task<string> GetAccessTokenForAppAsync(
string scope,
string? authenticationScheme = null,
string? tenant = null,
TokenAcquisitionOptions? tokenAcquisitionOptions = null,
string? authenticationScheme = null)
TokenAcquisitionOptions? tokenAcquisitionOptions = null)
{
// We could use MSI
if (scope is null)
Expand All @@ -123,11 +123,11 @@ public async Task<string> GetAccessTokenForAppAsync(
/// <inheritdoc/>
public Task<string> GetAccessTokenForUserAsync(
IEnumerable<string> scopes,
string? authenticationScheme = null,
string? tenantId = null,
string? userFlow = null,
ClaimsPrincipal? user = null,
TokenAcquisitionOptions? tokenAcquisitionOptions = null,
string? authenticationScheme = null)
TokenAcquisitionOptions? tokenAcquisitionOptions = null)
{
var httpContext = CurrentHttpContext;
string accessToken;
Expand Down Expand Up @@ -173,15 +173,15 @@ private string GetAccessToken(IHeaderDictionary? headers)
/// <inheritdoc/>
public async Task<AuthenticationResult> GetAuthenticationResultForUserAsync(
IEnumerable<string> scopes,
string? authenticationScheme = null,
string? tenantId = null,
string? userFlow = null,
ClaimsPrincipal? user = null,
TokenAcquisitionOptions? tokenAcquisitionOptions = null,
string? authenticationScheme = null)
TokenAcquisitionOptions? tokenAcquisitionOptions = null)
{
string? idToken = AppServicesAuthenticationInformation.GetIdToken(CurrentHttpContext?.Request?.Headers!);
ClaimsPrincipal? userClaims = AppServicesAuthenticationInformation.GetUser(CurrentHttpContext?.Request?.Headers!);
string accessToken = await GetAccessTokenForUserAsync(scopes, tenantId, userFlow, user, tokenAcquisitionOptions).ConfigureAwait(false);
string accessToken = await GetAccessTokenForUserAsync(scopes, tenantId: tenantId, userFlow: userFlow, user: user, tokenAcquisitionOptions: tokenAcquisitionOptions).ConfigureAwait(false);
string expiration = userClaims.FindFirstValue("exp");
DateTimeOffset dateTimeOffset = (expiration != null)
? DateTimeOffset.FromUnixTimeSeconds(long.Parse(expiration, CultureInfo.InvariantCulture))
Expand Down Expand Up @@ -230,8 +230,8 @@ public Task ReplyForbiddenWithWwwAuthenticateHeaderAsync(
public void ReplyForbiddenWithWwwAuthenticateHeader(
IEnumerable<string> scopes,
MsalUiRequiredException msalServiceException,
HttpResponse? httpResponse = null,
string? authenticationScheme = null)
string? authenticationScheme = null,
HttpResponse? httpResponse = null)
{
// Not implemented for the moment
throw new NotImplementedException();
Expand All @@ -240,9 +240,9 @@ public void ReplyForbiddenWithWwwAuthenticateHeader(
/// <inheritdoc/>
public Task<AuthenticationResult> GetAuthenticationResultForAppAsync(
string scope,
string? authenticationScheme = null,
string? tenant = null,
TokenAcquisitionOptions? tokenAcquisitionOptions = null,
string? authenticationScheme = null)
TokenAcquisitionOptions? tokenAcquisitionOptions = null)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public DownstreamWebApi(
/// <inheritdoc/>
public async Task<HttpResponseMessage> CallWebApiForUserAsync(
string serviceName,
string? authenticationScheme = null,
Action<DownstreamWebApiOptions>? calledDownstreamWebApiOptionsOverride = null,
ClaimsPrincipal? user = null,
StringContent? content = null,
string? authenticationScheme = null)
StringContent? content = null)
{
DownstreamWebApiOptions effectiveOptions = MergeOptions(serviceName, calledDownstreamWebApiOptionsOverride);

Expand Down Expand Up @@ -76,11 +76,11 @@ public async Task<HttpResponseMessage> CallWebApiForUserAsync(

AuthenticationResult authResult = await _tokenAcquisition.GetAuthenticationResultForUserAsync(
effectiveOptions.GetScopes(),
authenticationScheme,
effectiveOptions.Tenant,
userflow,
user,
effectiveOptions.TokenAcquisitionOptions,
authenticationScheme)
effectiveOptions.TokenAcquisitionOptions)
.ConfigureAwait(false);

using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage(
Expand All @@ -103,17 +103,17 @@ public async Task<HttpResponseMessage> CallWebApiForUserAsync(
public async Task<TOutput?> CallWebApiForUserAsync<TInput, TOutput>(
string serviceName,
TInput input,
string? authenticationScheme = null,
Action<DownstreamWebApiOptions>? downstreamWebApiOptionsOverride = null,
ClaimsPrincipal? user = null,
string? authenticationScheme = null)
ClaimsPrincipal? user = null)
where TOutput : class
{
HttpResponseMessage response = await CallWebApiForUserAsync(
serviceName,
authenticationScheme,
downstreamWebApiOptionsOverride,
user,
new StringContent(JsonSerializer.Serialize(input), Encoding.UTF8, "application/json"),
authenticationScheme).ConfigureAwait(false);
new StringContent(JsonSerializer.Serialize(input), Encoding.UTF8, "application/json")).ConfigureAwait(false);

try
{
Expand All @@ -139,9 +139,9 @@ public async Task<HttpResponseMessage> CallWebApiForUserAsync(
/// <inheritdoc/>
public async Task<HttpResponseMessage> CallWebApiForAppAsync(
string serviceName,
string? authenticationScheme = null,
Action<DownstreamWebApiOptions>? downstreamWebApiOptionsOverride = null,
StringContent? content = null,
string? authenticationScheme = null)
StringContent? content = null)
{
DownstreamWebApiOptions effectiveOptions = MergeOptions(serviceName, downstreamWebApiOptionsOverride);

Expand All @@ -156,9 +156,9 @@ public async Task<HttpResponseMessage> CallWebApiForAppAsync(

AuthenticationResult authResult = await _tokenAcquisition.GetAuthenticationResultForAppAsync(
effectiveOptions.Scopes,
authenticationScheme,
effectiveOptions.Tenant,
effectiveOptions.TokenAcquisitionOptions,
authenticationScheme)
effectiveOptions.TokenAcquisitionOptions)
.ConfigureAwait(false);

HttpResponseMessage response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public static class DownstreamWebApiGenericExtensions

HttpResponseMessage response = await downstreamWebApi.CallWebApiForUserAsync(
serviceName,
authenticationScheme,
PrepareOptions(relativePath, downstreamWebApiOptionsOverride, HttpMethod.Get),
user,
null,
authenticationScheme).ConfigureAwait(false);
null).ConfigureAwait(false);

return await ConvertToOutput<TOutput>(response).ConfigureAwait(false);
}
Expand Down Expand Up @@ -97,10 +97,10 @@ public static class DownstreamWebApiGenericExtensions

HttpResponseMessage response = await downstreamWebApi.CallWebApiForUserAsync(
serviceName,
authenticationScheme,
PrepareOptions(relativePath, downstreamWebApiOptionsOverride, HttpMethod.Post),
user,
input,
authenticationScheme).ConfigureAwait(false);
input).ConfigureAwait(false);

return await ConvertToOutput<TOutput>(response).ConfigureAwait(false);
}
Expand Down Expand Up @@ -142,10 +142,10 @@ public static async Task PutForUserAsync<TInput>(

await downstreamWebApi.CallWebApiForUserAsync(
serviceName,
authenticationScheme,
PrepareOptions(relativePath, downstreamWebApiOptionsOverride, HttpMethod.Put),
user,
input,
authenticationScheme).ConfigureAwait(false);
input).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -188,10 +188,10 @@ await downstreamWebApi.CallWebApiForUserAsync(

HttpResponseMessage response = await downstreamWebApi.CallWebApiForUserAsync(
serviceName,
authenticationScheme,
PrepareOptions(relativePath, downstreamWebApiOptionsOverride, HttpMethod.Put),
user,
input,
authenticationScheme).ConfigureAwait(false);
input).ConfigureAwait(false);

return await ConvertToOutput<TOutput>(response).ConfigureAwait(false);
}
Expand Down Expand Up @@ -229,10 +229,10 @@ await downstreamWebApi.CallWebApiForUserAsync(

HttpResponseMessage response = await downstreamWebApi.CallWebApiForUserAsync(
serviceName,
authenticationScheme,
downstreamWebApiOptionsOverride,
user,
null,
authenticationScheme).ConfigureAwait(false);
null).ConfigureAwait(false);

return await ConvertToOutput<TOutput>(response).ConfigureAwait(false);
}
Expand Down Expand Up @@ -272,10 +272,10 @@ public static async Task GetForUserAsync<TInput>(

await downstreamWebApi.CallWebApiForUserAsync(
serviceName,
authenticationScheme,
downstreamWebApiOptionsOverride,
user,
input,
authenticationScheme).ConfigureAwait(false);
input).ConfigureAwait(false);
}

private static StringContent ConvertFromInput<TInput>(TInput input)
Expand Down
Loading

0 comments on commit 222e76a

Please sign in to comment.