Skip to content

Commit 97c51de

Browse files
trwalketrwalkerayluogladjohn
authored
Adding authentication extension api to enable the extending of MSAL (#4859)
* Initial commit * Updating Core logic for CDT * Updates * Refactoring CdtAuthScheme Adding unit tests * Adding cache test case * Resolving issues * Update * Adding api to enable additional caching parameters * clean up * Clean up, Refactoring, Updating tests * Fixing test issue * Resolving build issue * Test fix * Refactoring CDT logic to make it extensible * hooking up addin * Adding support for arrays and objects * Hooking up Additional cache param logic * Clean up fix test * Adding integration test * Fixing tests * Ignoring test * Resolving build error * Making constraints an array * Updating CDT format * Moving CDT implementation to new project. * clean up * Moving cdt implementation to new project. Removing MSAL internal dependencies * Setting tokenType to internal * Resolving build issues * Refactoring CdtAuthScheme to use wilson * Resolving build errors * Revert "Resolving build errors" This reverts commit 68a8922. * Fixing error * Revert "Fixing error" This reverts commit 75e9955. * Revert "Revert "Resolving build errors"" This reverts commit 3fba7ba. * Revert "Resolving build errors" This reverts commit 68a8922. * Renaming authentication extension apis * Removing CDT * Ignoring failing test * Revert "Removing CDT" This reverts commit 54fb683. * Updating naming * Revert "Revert "Removing CDT"" This reverts commit fba6bd9. * Update Microsoft.Identity.Client.csproj * Revert "Revert "Revert "Removing CDT""" This reverts commit 2a96823. * Revert "Revert "Revert "Revert "Removing CDT"""" This reverts commit ab14305. * Refactoring. Clean up. Removing CDT * Additional test cases * Clean up * Refactoring clean up * Enabling CdtTelemetry * Renaming * TestFix * Apply suggestions from code review Co-authored-by: Ray Luo <[email protected]> Co-authored-by: Gladwin Johnson <[email protected]> * Adding test * Fixing test issue --------- Co-authored-by: trwalke <[email protected]> Co-authored-by: Ray Luo <[email protected]> Co-authored-by: Gladwin Johnson <[email protected]>
1 parent 9c40835 commit 97c51de

File tree

40 files changed

+536
-128
lines changed

40 files changed

+536
-128
lines changed

src/client/Microsoft.Identity.Client/ApiConfig/AbstractAcquireTokenParameterBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ public T WithB2CAuthority(string authorityUri)
334334
return this as T;
335335
}
336336

337-
internal /* for testing */ T WithAuthenticationScheme(IAuthenticationScheme scheme)
337+
internal /* for testing */ T WithAuthenticationOperation(IAuthenticationOperation authOperation)
338338
{
339-
CommonParameters.AuthenticationScheme = scheme ?? throw new ArgumentNullException(nameof(scheme));
339+
ValidateUseOfExperimentalFeature();
340+
CommonParameters.AuthenticationOperation = authOperation ?? throw new ArgumentNullException(nameof(authOperation));
340341
return this as T;
341342
}
342343
}

src/client/Microsoft.Identity.Client/ApiConfig/AbstractConfidentialClientAcquireTokenParameterBuilder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.ComponentModel;
7+
using System.Security.Cryptography.X509Certificates;
68
using System.Threading;
79
using System.Threading.Tasks;
10+
using Microsoft.Identity.Client.ApiConfig;
811
using Microsoft.Identity.Client.ApiConfig.Executors;
912
using Microsoft.Identity.Client.AppConfig;
1013
using Microsoft.Identity.Client.AuthScheme.PoP;
@@ -82,7 +85,7 @@ public T WithProofOfPossession(PoPAuthenticationConfiguration popAuthenticationC
8285

8386
CommonParameters.PopAuthenticationConfiguration = popAuthenticationConfiguration ?? throw new ArgumentNullException(nameof(popAuthenticationConfiguration));
8487

85-
CommonParameters.AuthenticationScheme = new PopAuthenticationScheme(CommonParameters.PopAuthenticationConfiguration, ServiceBundle);
88+
CommonParameters.AuthenticationOperation = new PopAuthenticationOperation(CommonParameters.PopAuthenticationConfiguration, ServiceBundle);
8689

8790
return this as T;
8891
}

src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenByUsernamePasswordParameterBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public AcquireTokenByUsernamePasswordParameterBuilder WithProofOfPossession(stri
102102
popConfig.HttpMethod = httpMethod;
103103

104104
CommonParameters.PopAuthenticationConfiguration = popConfig;
105-
CommonParameters.AuthenticationScheme = new PopBrokerAuthenticationScheme();
105+
CommonParameters.AuthenticationOperation = new PopBrokerAuthenticationOperation();
106106

107107
return this;
108108
}

src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenInteractiveParameterBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public AcquireTokenInteractiveParameterBuilder WithProofOfPossession(string nonc
384384
popConfig.HttpMethod = httpMethod;
385385

386386
CommonParameters.PopAuthenticationConfiguration = popConfig;
387-
CommonParameters.AuthenticationScheme = new PopBrokerAuthenticationScheme();
387+
CommonParameters.AuthenticationOperation = new PopBrokerAuthenticationOperation();
388388

389389
return this;
390390
}

src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenSilentParameterBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public AcquireTokenSilentParameterBuilder WithProofOfPossession(PoPAuthenticatio
169169

170170
CommonParameters.PopAuthenticationConfiguration = popAuthenticationConfiguration ?? throw new ArgumentNullException(nameof(popAuthenticationConfiguration));
171171

172-
CommonParameters.AuthenticationScheme = new PopAuthenticationScheme(CommonParameters.PopAuthenticationConfiguration, ServiceBundle);
172+
CommonParameters.AuthenticationOperation = new PopAuthenticationOperation(CommonParameters.PopAuthenticationConfiguration, ServiceBundle);
173173

174174
return this;
175175
}
@@ -232,20 +232,20 @@ public AcquireTokenSilentParameterBuilder WithProofOfPossession(string nonce, Ht
232232
popConfig.HttpMethod = httpMethod ?? throw new ArgumentNullException(nameof(httpMethod));
233233
popConfig.Nonce = nonce;
234234

235-
IAuthenticationScheme authenticationScheme;
235+
IAuthenticationOperation authenticationScheme;
236236

237237
//POP Auth scheme should not wrap and sign token when broker is enabled for public clients
238238
if (ServiceBundle.Config.IsBrokerEnabled)
239239
{
240240
popConfig.SignHttpRequest = false;
241-
authenticationScheme = new PopBrokerAuthenticationScheme();
241+
authenticationScheme = new PopBrokerAuthenticationOperation();
242242
}
243243
else
244244
{
245-
authenticationScheme = new PopAuthenticationScheme(popConfig, ServiceBundle);
245+
authenticationScheme = new PopAuthenticationOperation(popConfig, ServiceBundle);
246246
}
247247
CommonParameters.PopAuthenticationConfiguration = popConfig;
248-
CommonParameters.AuthenticationScheme = authenticationScheme;
248+
CommonParameters.AuthenticationOperation = authenticationScheme;
249249

250250
return this;
251251
}

src/client/Microsoft.Identity.Client/ApiConfig/Parameters/AcquireTokenCommonParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class AcquireTokenCommonParameters
2424
public IDictionary<string, string> ExtraQueryParameters { get; set; }
2525
public string Claims { get; set; }
2626
public AuthorityInfo AuthorityOverride { get; set; }
27-
public IAuthenticationScheme AuthenticationScheme { get; set; } = new BearerAuthenticationScheme();
27+
public IAuthenticationOperation AuthenticationOperation { get; set; } = new BearerAuthenticationOperation();
2828
public IDictionary<string, string> ExtraHttpHeaders { get; set; }
2929
public PoPAuthenticationConfiguration PopAuthenticationConfiguration { get; set; }
3030
public Func<OnBeforeTokenRequestData, Task> OnBeforeTokenRequestHandler { get; internal set; }

src/client/Microsoft.Identity.Client/AuthScheme/AuthSchemeHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public static bool StoreTokenTypeInCacheKey(string tokenType)
1919
{
2020
if (string.Equals(
2121
tokenType,
22-
BearerAuthenticationScheme.BearerTokenType,
22+
BearerAuthenticationOperation.BearerTokenType,
2323
StringComparison.OrdinalIgnoreCase))
2424
{
2525
return false;
2626
}
2727

2828
if (string.Equals(
2929
tokenType,
30-
SSHCertAuthenticationScheme.SSHCertTokenType,
30+
SSHCertAuthenticationOperation.SSHCertTokenType,
3131
StringComparison.OrdinalIgnoreCase))
3232
{
3333
return false;

src/client/Microsoft.Identity.Client/AuthScheme/Bearer/BearerAuthenticationScheme.cs renamed to src/client/Microsoft.Identity.Client/AuthScheme/Bearer/BearerAuthenticationOperation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77

88
namespace Microsoft.Identity.Client.AuthScheme.Bearer
99
{
10-
internal class BearerAuthenticationScheme : IAuthenticationScheme
10+
internal class BearerAuthenticationOperation : IAuthenticationOperation
1111
{
1212
internal const string BearerTokenType = "bearer";
1313

14-
public TokenType TelemetryTokenType => TokenType.Bearer;
14+
public int TelemetryTokenType => (int)TokenType.Bearer;
1515

1616
public string AuthorizationHeaderPrefix => "Bearer";
1717

1818
public string AccessTokenType => BearerTokenType;
1919

2020
public string KeyId => null;
2121

22-
public string FormatAccessToken(MsalAccessTokenCacheItem msalAccessTokenCacheItem)
22+
public void FormatResult(AuthenticationResult authenticationResult)
2323
{
24-
return msalAccessTokenCacheItem.Secret;
24+
// no-op
2525
}
2626

2727
public IReadOnlyDictionary<string, string> GetTokenRequestParams()

src/client/Microsoft.Identity.Client/AuthScheme/IAuthenticationScheme.cs renamed to src/client/Microsoft.Identity.Client/AuthScheme/IAuthenticationOperation.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@ namespace Microsoft.Identity.Client.AuthScheme
99
/// <summary>
1010
/// Used to modify the experience depending on the type of token asked.
1111
/// </summary>
12-
internal interface IAuthenticationScheme
12+
public interface IAuthenticationOperation
1313
{
1414
/// <summary>
15-
/// Value to log to telemetry to indicate pop usage.
15+
/// Value to log to telemetry
16+
/// Values available:
17+
///
18+
/// Bearer token type.
19+
/// Bearer = 1
20+
///
21+
/// Pop token type.
22+
/// Pop = 2,
23+
///
24+
/// Ssh-cert token type.
25+
/// SshCert = 3,
26+
///
27+
/// External token type.
28+
/// External = 4,
29+
///
30+
/// Extension token type.
31+
/// Extension = 5
1632
/// </summary>
17-
TokenType TelemetryTokenType { get; }
33+
int TelemetryTokenType { get; }
1834

1935
/// <summary>
2036
/// Prefix for the HTTP header that has the token. E.g. "Bearer" or "POP"
@@ -37,7 +53,7 @@ internal interface IAuthenticationScheme
3753
/// <summary>
3854
/// Creates the access token that goes into an Authorization HTTP header.
3955
/// </summary>
40-
string FormatAccessToken(MsalAccessTokenCacheItem msalAccessTokenCacheItem);
56+
void FormatResult(AuthenticationResult authenticationResult);
4157

4258
/// <summary>
4359
/// Expected to match the token_type parameter returned by ESTS. Used to disambiguate

src/client/Microsoft.Identity.Client/AuthScheme/PoP/InMemoryCryptoProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33

44
using System;
55
using System.Security.Cryptography;
6-
using Microsoft.Identity.Client.AuthScheme.PoP;
76
using Microsoft.Identity.Client.Utils;
87

98
namespace Microsoft.Identity.Client.AuthScheme.PoP
109
{
11-
1210
/// <summary>
1311
/// The default implementation will store a key in memory
1412
/// </summary>

0 commit comments

Comments
 (0)