/// <summary> /// Attempts to log into an external repository connection. /// </summary> /// <param name="targetID">The connection to authenticate against.</param> /// <param name="authentication">The authentication details to use.</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>The repository state after login attempt.</returns> public RepositoryAuthenticationStatus LogInWithExtensionAuthentication( string targetID, RepositoryAuthentication authentication, CancellationToken token = default(CancellationToken)) { // Execute the async method. return(this.LogInWithExtensionAuthenticationAsync(targetID, authentication, token) .ConfigureAwait(false) .GetAwaiter() .GetResult()); }
/// <summary> /// Attempts to log into an external repository connection. /// </summary> /// <param name="targetID">The connection to authenticate against.</param> /// <param name="authentication">The authentication details to use.</param> /// <param name="token">A cancellation token for the request.</param> /// <returns>An awaitable task.</returns> public async Task <RepositoryAuthenticationStatus> LogInWithExtensionAuthenticationAsync( string targetID, RepositoryAuthentication authentication, CancellationToken token = default(CancellationToken)) { // Sanity. if (null == targetID) { throw new ArgumentNullException(nameof(targetID)); } if (string.IsNullOrWhiteSpace(targetID)) { throw new ArgumentException("The target cannot be null or empty.", nameof(targetID)); } if (null == authentication) { throw new ArgumentNullException(nameof(authentication)); } if (string.IsNullOrWhiteSpace(authentication.ConfigurationName)) { throw new ArgumentException("The authentication plugin configuration name must be provided.", nameof(authentication)); } // Create the request. var request = new RestRequest($"/REST/repositories/{HttpUtility.UrlEncode(targetID)}/session.aspx"); // If authentication token is a blank string, replace it with null. // This is because the remote end tests against null. if (string.IsNullOrWhiteSpace(authentication.AuthenticationToken)) { authentication.AuthenticationToken = null; } // Set the request body. request.AddJsonBody(authentication); // Make the request and get the response. var response = await this.MFWSClient.Post <RepositoryAuthenticationStatus>(request, token) .ConfigureAwait(false); // Return the data. return(response.Data); }
public async Task LogInWithExtensionAuthenticationAsync() { // Set the target ID. var targetID = "hello world"; // Create our test runner. var runner = new RestApiTestRunner <RepositoryAuthenticationStatus>(Method.POST, $"/REST/repositories/{HttpUtility.UrlEncode(targetID)}/session.aspx"); // Create the body. var authentication = new RepositoryAuthentication() { ConfigurationName = "hello" }; // Set the expected body. runner.SetExpectedRequestBody(authentication); // Execute. await runner.MFWSClient.ExtensionAuthenticationOperations.LogInWithExtensionAuthenticationAsync(targetID, authentication); // Verify. runner.Verify(); }