Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make cca creation not async #1085

Merged
merged 2 commits into from
Mar 24, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public AppServicesAuthenticationTokenAcquisition(
_tokenCacheProvider = tokenCacheProvider;
}

private async Task<IConfidentialClientApplication> GetOrCreateApplication()
private IConfidentialClientApplication GetOrCreateApplication()
{
if (_confidentialClientApplication == null)
{
Expand All @@ -81,8 +81,8 @@ private async Task<IConfidentialClientApplication> GetOrCreateApplication()
_confidentialClientApplication = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(options)
.WithHttpClientFactory(_httpClientFactory)
.Build();
await _tokenCacheProvider.InitializeAsync(_confidentialClientApplication.AppTokenCache).ConfigureAwait(false);
await _tokenCacheProvider.InitializeAsync(_confidentialClientApplication.UserTokenCache).ConfigureAwait(false);
_tokenCacheProvider.Initialize(_confidentialClientApplication.AppTokenCache);
_tokenCacheProvider.Initialize(_confidentialClientApplication.UserTokenCache);
}

return _confidentialClientApplication;
Expand All @@ -100,7 +100,7 @@ public async Task<string> GetAccessTokenForAppAsync(
throw new ArgumentNullException(nameof(scope));
}

var app = await GetOrCreateApplication().ConfigureAwait(false);
var app = GetOrCreateApplication();
AuthenticationResult result = await app.AcquireTokenForClient(new string[] { scope })
.ExecuteAsync()
.ConfigureAwait(false);
Expand Down Expand Up @@ -176,7 +176,14 @@ public async Task<AuthenticationResult> GetAuthenticationResultForUserAsync(
}

/// <inheritdoc/>
public async Task ReplyForbiddenWithWwwAuthenticateHeaderAsync(IEnumerable<string> scopes, MsalUiRequiredException msalServiceException, HttpResponse? httpResponse = null)
public Task ReplyForbiddenWithWwwAuthenticateHeaderAsync(IEnumerable<string> scopes, MsalUiRequiredException msalServiceException, HttpResponse? httpResponse = null)
{
// Not implemented for the moment
throw new NotImplementedException();
}

/// <inheritdoc/>
public void ReplyForbiddenWithWwwAuthenticateHeader(IEnumerable<string> scopes, MsalUiRequiredException msalServiceException, HttpResponse? httpResponse = null)
{
// Not implemented for the moment
throw new NotImplementedException();
Expand All @@ -188,6 +195,5 @@ public Task<AuthenticationResult> GetAuthenticationResultForAppAsync(string scop
throw new NotImplementedException();
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

}
}
4 changes: 3 additions & 1 deletion src/Microsoft.Identity.Web/Constants/IDWebErrorMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ internal static class IDWebErrorMessage
"StoreName must be empty or one of '{0}'. ";

// Obsolete messages IDW10800 = "IDW10800:"
public const string AadIssuerValidatorGetIssuerValidatorIsObsolete = "IDW10800: Use MicrosoftIdentityIssuerValidatorFactory.GetAadIssuerValidator. See https://aka.ms/ms-id-web/1.2.0";
public const string AadIssuerValidatorGetIssuerValidatorIsObsolete = "IDW10800: Use MicrosoftIdentityIssuerValidatorFactory.GetAadIssuerValidator. See https://aka.ms/ms-id-web/1.2.0. ";
public const string InitializeAsyncIsObsolete = "IDW10801: Use Initialize instead. See https://aka.ms/ms-id-web/1.9.0. ";
public const string ReplyForbiddenWithWwwAuthenticateHeaderAsyncIsObsolete = "IDW10801: Use ReplyForbiddenWithWwwAuthenticateHeader instead. See https://aka.ms/ms-id-web/1.9.0. ";
}
}
15 changes: 15 additions & 0 deletions src/Microsoft.Identity.Web/ITokenAcquisition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
Expand Down Expand Up @@ -92,6 +93,19 @@ Task<AuthenticationResult> GetAuthenticationResultForAppAsync(
string? tenant = null,
TokenAcquisitionOptions? tokenAcquisitionOptions = null);

/// <summary>
/// Used in web APIs (which therefore cannot have an interaction with the user).
/// Replies to the client through the HttpResponse by sending a 403 (forbidden) and populating wwwAuthenticateHeaders so that
/// the client can trigger an interaction with the user so the user can consent to more scopes.
/// </summary>
/// <param name="scopes">Scopes to consent to.</param>
/// <param name="msalServiceException"><see cref="MsalUiRequiredException"/> triggering the challenge.</param>
/// <param name="httpResponse">The <see cref="HttpResponse"/> to update.</param>
void ReplyForbiddenWithWwwAuthenticateHeader(
IEnumerable<string> scopes,
MsalUiRequiredException msalServiceException,
HttpResponse? httpResponse = null);

/// <summary>
/// Used in web APIs (which therefore cannot have an interaction with the user).
/// Replies to the client through the HttpResponse by sending a 403 (forbidden) and populating wwwAuthenticateHeaders so that
Expand All @@ -101,6 +115,7 @@ Task<AuthenticationResult> GetAuthenticationResultForAppAsync(
/// <param name="msalServiceException"><see cref="MsalUiRequiredException"/> triggering the challenge.</param>
/// <param name="httpResponse">The <see cref="HttpResponse"/> to update.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
[Obsolete(IDWebErrorMessage.InitializeAsyncIsObsolete, true)]
Task ReplyForbiddenWithWwwAuthenticateHeaderAsync(
IEnumerable<string> scopes,
MsalUiRequiredException msalServiceException,
Expand Down
54 changes: 44 additions & 10 deletions src/Microsoft.Identity.Web/Microsoft.Identity.Web.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading