-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enabling ROPC on CCA * Clean up. Adding tests. * Refactoring. Adding explicit interface for ROPC with CCA * Update src/client/Microsoft.Identity.Client/IByUsernameAndPassword.cs Co-authored-by: Neha Bhargava <[email protected]> * Clean up. Refactoring * clean up --------- Co-authored-by: trwalke <[email protected]> Co-authored-by: Gladwin Johnson <[email protected]> Co-authored-by: Neha Bhargava <[email protected]>
- Loading branch information
1 parent
89dba0a
commit adf5dab
Showing
9 changed files
with
241 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...dentity.Client/ApiConfig/AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Net.Http; | ||
using System.Security; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Identity.Client.ApiConfig.Executors; | ||
using Microsoft.Identity.Client.ApiConfig.Parameters; | ||
using Microsoft.Identity.Client.AppConfig; | ||
using Microsoft.Identity.Client.AuthScheme.PoP; | ||
using Microsoft.Identity.Client.PlatformsCommon.Shared; | ||
using Microsoft.Identity.Client.TelemetryCore.Internal.Events; | ||
|
||
namespace Microsoft.Identity.Client | ||
{ | ||
/// <summary> | ||
/// Parameter builder for the <see cref="IConfidentialClientApplication.AcquireTokenByUsernamePassword(IEnumerable{string}, string, string)"/> | ||
Check warning on line 21 in src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.cs GitHub Actions / Run performance benchmarks
Check warning on line 21 in src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder.cs GitHub Actions / Run performance benchmarks
|
||
/// operation. See https://aka.ms/msal-net-up | ||
/// </summary> | ||
public sealed class AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder : | ||
AbstractConfidentialClientAcquireTokenParameterBuilder<AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder> | ||
{ | ||
private AcquireTokenByUsernamePasswordParameters Parameters { get; } = new AcquireTokenByUsernamePasswordParameters(); | ||
|
||
internal AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder( | ||
IConfidentialClientApplicationExecutor confidentialClientApplicationExecutor, | ||
string username, | ||
string password) | ||
: base(confidentialClientApplicationExecutor) | ||
{ | ||
Parameters.Username = username; | ||
Parameters.Password = password; | ||
} | ||
|
||
internal static AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder Create( | ||
IConfidentialClientApplicationExecutor confidentialClientApplicationExecutor, | ||
IEnumerable<string> scopes, | ||
string username, | ||
string password) | ||
{ | ||
if (string.IsNullOrEmpty(username)) | ||
{ | ||
throw new ArgumentNullException(nameof(username)); | ||
} | ||
|
||
if (string.IsNullOrEmpty(password)) | ||
{ | ||
throw new ArgumentNullException(nameof(password)); | ||
} | ||
|
||
return new AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder(confidentialClientApplicationExecutor, username, password) | ||
.WithScopes(scopes); | ||
} | ||
|
||
/// <inheritdoc/> | ||
internal override Task<AuthenticationResult> ExecuteInternalAsync(CancellationToken cancellationToken) | ||
{ | ||
return ConfidentialClientApplicationExecutor.ExecuteAsync(CommonParameters, Parameters, cancellationToken); | ||
} | ||
|
||
/// <inheritdoc/> | ||
internal override ApiEvent.ApiIds CalculateApiEventId() | ||
{ | ||
return ApiEvent.ApiIds.AcquireTokenByUsernamePassword; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/client/Microsoft.Identity.Client/IByUsernameAndPassword.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Identity.Client.ApiConfig; | ||
|
||
namespace Microsoft.Identity.Client | ||
{ | ||
/// <summary> | ||
/// Provides an explicit interface for using Resource Owner Password Grant on Confidential Client. | ||
/// </summary> | ||
public interface IByUsernameAndPassword | ||
{ | ||
/// <summary> | ||
/// Acquires a token without user interaction using username and password authentication. | ||
/// This method does not look in the token cache, but stores the result in it. Before calling this method, use other methods | ||
/// such as <see cref="IClientApplicationBase.AcquireTokenSilent(IEnumerable{string}, IAccount)"/> to check the token cache. | ||
/// </summary> | ||
/// <param name="scopes">Scopes requested to access a protected API.</param> | ||
/// <param name="username">Identifier of the user, application requests token on behalf of. | ||
/// Generally in UserPrincipalName (UPN) format, e.g. <c>[email protected]</c></param> | ||
/// <param name="password">User password as a string.</param> | ||
/// <returns>A builder enabling you to add optional parameters before executing the token request.</returns> | ||
/// <remarks> | ||
/// Available only for .NET Framework and .NET Core applications. See <see href="https://aka.ms/msal-net-up">our documentation</see> for details. | ||
/// </remarks> | ||
AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder AcquireTokenByUsernamePassword(IEnumerable<string> scopes, string username, string password); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters