From 69a8fb796686ba28ebd5a31eb136d05d3b057cb0 Mon Sep 17 00:00:00 2001
From: Zach Teutsch <88554871+zateutsch@users.noreply.github.com>
Date: Tue, 25 Jan 2022 22:21:14 -0800
Subject: [PATCH 1/3] Added optionak scopes parameter
---
CommunityToolkit.Authentication.Uwp/WindowsProvider.cs | 7 ++++---
CommunityToolkit.Authentication/BaseProvider.cs | 2 +-
CommunityToolkit.Authentication/IProvider.cs | 3 ++-
CommunityToolkit.Authentication/MockProvider.cs | 2 +-
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs b/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs
index b0f1235..2a5434a 100644
--- a/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs
+++ b/CommunityToolkit.Authentication.Uwp/WindowsProvider.cs
@@ -184,16 +184,17 @@ public override async Task SignOutAsync()
}
///
- public override async Task GetTokenAsync(bool silentOnly = false)
+ public override async Task GetTokenAsync(bool silentOnly = false, string[] scopes = null)
{
await SemaphoreSlim.WaitAsync();
try
{
- var scopes = _scopes;
+ // use request specific scopes if not null, otherwise use class scopes
+ var authenticationScopes = scopes ?? this._scopes;
// Attempt to authenticate silently.
- var authResult = await AuthenticateSilentAsync(scopes);
+ var authResult = await AuthenticateSilentAsync(authenticationScopes);
// Authenticate with user interaction as appropriate.
if (authResult?.ResponseStatus != WebTokenRequestStatus.Success)
diff --git a/CommunityToolkit.Authentication/BaseProvider.cs b/CommunityToolkit.Authentication/BaseProvider.cs
index cbeaeb6..4a0c5d5 100644
--- a/CommunityToolkit.Authentication/BaseProvider.cs
+++ b/CommunityToolkit.Authentication/BaseProvider.cs
@@ -52,7 +52,7 @@ public BaseProvider()
public abstract Task AuthenticateRequestAsync(HttpRequestMessage request);
///
- public abstract Task GetTokenAsync(bool silentOnly = false);
+ public abstract Task GetTokenAsync(bool silentOnly = false, string[] scopes = null);
///
public abstract Task SignInAsync();
diff --git a/CommunityToolkit.Authentication/IProvider.cs b/CommunityToolkit.Authentication/IProvider.cs
index cd065a2..2e126e0 100644
--- a/CommunityToolkit.Authentication/IProvider.cs
+++ b/CommunityToolkit.Authentication/IProvider.cs
@@ -39,8 +39,9 @@ public interface IProvider
/// Retrieve a token for the authenticated user.
///
/// Determines if the acquisition should be done without prompts to the user.
+ /// Optional param for setting scopes specific to this token request
/// A token string for the authenticated user.
- Task GetTokenAsync(bool silentOnly = false);
+ Task GetTokenAsync(bool silentOnly = false, string[] scopes = null);
///
/// Sign in the user.
diff --git a/CommunityToolkit.Authentication/MockProvider.cs b/CommunityToolkit.Authentication/MockProvider.cs
index d66e63b..67e261d 100644
--- a/CommunityToolkit.Authentication/MockProvider.cs
+++ b/CommunityToolkit.Authentication/MockProvider.cs
@@ -52,7 +52,7 @@ public override async Task AuthenticateRequestAsync(HttpRequestMessage request)
}
///
- public override Task GetTokenAsync(bool silentOnly = false)
+ public override Task GetTokenAsync(bool silentOnly = false, string[] scopes = null)
{
return Task.FromResult("");
}
From 4b4c216dac1bc0f9a9c61d8e66332f7552d9ffba Mon Sep 17 00:00:00 2001
From: Zach Teutsch <88554871+zateutsch@users.noreply.github.com>
Date: Wed, 26 Jan 2022 10:48:26 -0800
Subject: [PATCH 2/3] Added arg to MsalProvider as well
---
CommunityToolkit.Authentication.Msal/MsalProvider.cs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/CommunityToolkit.Authentication.Msal/MsalProvider.cs b/CommunityToolkit.Authentication.Msal/MsalProvider.cs
index 3adf77a..9b90884 100644
--- a/CommunityToolkit.Authentication.Msal/MsalProvider.cs
+++ b/CommunityToolkit.Authentication.Msal/MsalProvider.cs
@@ -171,9 +171,10 @@ public override async Task SignOutAsync()
}
///
- public override Task GetTokenAsync(bool silentOnly = false)
+ public override Task GetTokenAsync(bool silentOnly = false, string[] scopes = null)
{
- return this.GetTokenWithScopesAsync(Scopes, silentOnly);
+ var withScopes = scopes ?? this.Scopes;
+ return this.GetTokenWithScopesAsync(withScopes, silentOnly);
}
///
From 3fcae7cc5f1bfe3b66bd24deba68e62b9523900f Mon Sep 17 00:00:00 2001
From: Zach Teutsch <88554871+zateutsch@users.noreply.github.com>
Date: Wed, 26 Jan 2022 10:56:01 -0800
Subject: [PATCH 3/3] Typo fix
---
CommunityToolkit.Authentication/IProvider.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CommunityToolkit.Authentication/IProvider.cs b/CommunityToolkit.Authentication/IProvider.cs
index 2e126e0..a9d0e84 100644
--- a/CommunityToolkit.Authentication/IProvider.cs
+++ b/CommunityToolkit.Authentication/IProvider.cs
@@ -39,7 +39,7 @@ public interface IProvider
/// Retrieve a token for the authenticated user.
///
/// Determines if the acquisition should be done without prompts to the user.
- /// Optional param for setting scopes specific to this token request
+ /// Optional parameter for setting scopes specific to this token request.
/// A token string for the authenticated user.
Task GetTokenAsync(bool silentOnly = false, string[] scopes = null);