Closed brekkjen closed 2 years ago
MsalProvider
constructor:/// <summary>
/// Initializes a new instance of the <see cref="MsalProvider"/> class with default configuration values.
/// </summary>
/// <param name="clientId">Registered client id in Azure Acitve Directory.</param>
/// <param name="redirectUri">RedirectUri for auth response.</param>
/// <param name="scopes">List of Scopes to initially request.</param>
/// <param name="autoSignIn">Determines whether the provider attempts to silently log in upon creation.</param>
/// <param name="listWindowsWorkAndSchoolAccounts">Determines if organizational accounts should be enabled/disabled.</param>
/// <param name="tenantId">Registered tenant id in Azure Active Directory.</param>
public MsalProvider(string clientId, string[] scopes = null, string redirectUri = null, bool autoSignIn = true, bool listWindowsWorkAndSchoolAccounts = true, string tenantId = null) { ... }
WindowsProvider
has yet to be evaluated/updated.
Just tested this and I'm getting an error if providing TenantId because it will cause both TenantId and WithAuthority to be specified and those two are mutually exlusive. I solved it like this:
protected IPublicClientApplication CreatePublicClientApplication(string clientId, string tenantId, string redirectUri, bool listWindowsWorkAndSchoolAccounts)
{
var authority = listWindowsWorkAndSchoolAccounts ? AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount : AadAuthorityAudience.PersonalMicrosoftAccount;
var clientBuilder = PublicClientApplicationBuilder.Create(clientId)
//.WithAuthority(AzureCloudInstance.AzurePublic, authority)
.WithClientName(ProviderManager.ClientName)
.WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString());
if (tenantId != null)
{
clientBuilder = clientBuilder.WithTenantId(tenantId);
}
else
{
clientBuilder = clientBuilder.WithAuthority(AzureCloudInstance.AzurePublic, authority);
}
#if WINDOWS_UWP || NET5_0_WINDOWS10_0_17763_0
clientBuilder = clientBuilder.WithBroker();
#elif NETCOREAPP3_1
clientBuilder = clientBuilder.WithWindowsBroker();
#endif
clientBuilder = (redirectUri != null)
? clientBuilder.WithRedirectUri(redirectUri)
: clientBuilder.WithDefaultRedirectUri();
return clientBuilder.Build();
}
Hey, great catch @brekkjen. Any interest in submitting a PR? If not I can do it this afternoon. But since you have the solution already I figured I'd check with you first :)
Done, hope I'm doing this right... My first PR :)
Great work Leif, and thanks for getting involved with the project! ⭐🚀
Describe the problem this feature would solve
I cant find a way to specify TenantId when creating the GlobalProvider
Describe the solution
Please make it possible to specify TenantId
Describe alternatives you've considered
Additional context & Screenshots