Skip to content
Merged
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
25 changes: 8 additions & 17 deletions CommunityToolkit.Authentication.Uwp/WindowsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Windows.Networking.Connectivity;
using Windows.Security.Authentication.Web;
using Windows.Security.Authentication.Web.Core;
using Windows.Security.Credentials;
Expand All @@ -23,14 +22,6 @@ namespace CommunityToolkit.Authentication
/// </summary>
public class WindowsProvider : BaseProvider
{
/// <summary>
/// Gets the redirect uri value based on the current app callback uri.
/// Used for configuring the Azure app registration.
/// </summary>
public static string RedirectUri => string.Format("ms-appx-web://Microsoft.AAD.BrokerPlugIn/{0}", WebAuthenticationBroker.GetCurrentApplicationCallbackUri().Host.ToUpper());

private static readonly SemaphoreSlim SemaphoreSlim = new(1);

private const string AuthenticationHeaderScheme = "Bearer";
private const string GraphResourcePropertyKey = "resource";
private const string GraphResourcePropertyValue = "https://graph.microsoft.com";
Expand All @@ -41,13 +32,21 @@ public class WindowsProvider : BaseProvider
private const string SettingsKeyAccountId = "WindowsProvider_AccountId";
private const string SettingsKeyProviderId = "WindowsProvider_ProviderId";

private static readonly SemaphoreSlim SemaphoreSlim = new (1);

// Default/minimal scopes for authentication, if none are provided.
private static readonly string[] DefaultScopes = { "User.Read" };

// The default account providers available in the AccountsSettingsPane.
// Default is Msa because it does not require any additional configuration
private static readonly WebAccountProviderType DefaultWebAccountsProviderType = WebAccountProviderType.Msa;

/// <summary>
/// Gets the redirect uri value based on the current app callback uri.
/// Used for configuring the Azure app registration.
/// </summary>
public static string RedirectUri => string.Format("ms-appx-web://Microsoft.AAD.BrokerPlugIn/{0}", WebAuthenticationBroker.GetCurrentApplicationCallbackUri().Host.ToUpper());

/// <inheritdoc />
public override string CurrentAccountId => _webAccount?.Id;

Expand Down Expand Up @@ -188,14 +187,6 @@ public override async Task<string> GetTokenAsync(bool silentOnly = false)

try
{
var internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
if (internetConnectionProfile == null)
{
// We are not online, no token for you.
// TODO: Is there anything special to do when we go offline?
return null;
}

var scopes = _scopes;

// Attempt to authenticate silently.
Expand Down