private static Expression <Func <StartDeviceAuthorizationRequest, bool> > MatchesRequest(
     StartDeviceAuthorizationRequest expectedRequest)
 {
     return(request => request.ClientSecret == expectedRequest.ClientSecret &&
            request.ClientId == expectedRequest.ClientId &&
            request.StartUrl == expectedRequest.StartUrl);
 }
 public void AssertStartDeviceAuthorizationAsyncRequest(StartDeviceAuthorizationRequest expectedRequest)
 {
     OidcClient.Verify(
         mock => mock.StartDeviceAuthorizationAsync(
             It.Is <StartDeviceAuthorizationRequest>(MatchesRequest(expectedRequest)),
             It.IsAny <CancellationToken>()), Times.Once);
 }
Beispiel #3
0
        public static GetSsoTokenResponse GetSsoToken(IAmazonSSOOIDC client, GetSsoTokenRequest request, IGetSsoTokenContext context)
        {
            var registerClientRequest = new RegisterClientRequest()
            {
                ClientName = request.ClientName,
                ClientType = request.ClientType,
            };

            InternalSDKUtils.ApplyValues(registerClientRequest, request.AdditionalProperties);

            var registerClientResponse = client.RegisterClient(registerClientRequest);


            var startDeviceAuthorizationRequest = new StartDeviceAuthorizationRequest()
            {
                ClientSecret = registerClientResponse.ClientSecret,
                ClientId     = registerClientResponse.ClientId,
                StartUrl     = request.StartUrl,
            };

            InternalSDKUtils.ApplyValues(startDeviceAuthorizationRequest, request.AdditionalProperties);

            var startDeviceAuthorizationResponse = client.StartDeviceAuthorization(startDeviceAuthorizationRequest);


            // Spec: The expiration time must be calculated by adding the number of seconds
            // returned by StartDeviceAuthorization (ExpiresIn) to the current time.
            DateTime deviceCodeExpiration = DateTime.UtcNow.AddSeconds(startDeviceAuthorizationResponse.ExpiresIn);

            request.SsoVerificationCallback(new SsoVerificationArguments()
            {
                UserCode                = startDeviceAuthorizationResponse.UserCode,
                VerificationUri         = startDeviceAuthorizationResponse.VerificationUri,
                VerificationUriComplete = startDeviceAuthorizationResponse.VerificationUriComplete,
            });


            var createTokenRequest = new CreateTokenRequest()
            {
                ClientId     = registerClientResponse.ClientId,
                ClientSecret = registerClientResponse.ClientSecret,
                GrantType    = CreateTokenGrantType,
                DeviceCode   = startDeviceAuthorizationResponse.DeviceCode,
            };

            InternalSDKUtils.ApplyValues(request, request.AdditionalProperties);

            var ssoToken = PollForSsoToken(client,
                                           createTokenRequest,
                                           startDeviceAuthorizationResponse.Interval,
                                           deviceCodeExpiration,
                                           context);

            return(new GetSsoTokenResponse()
            {
                AccessToken = ssoToken.AccessToken,
                ExpiresAt = DateTime.UtcNow.AddSeconds(ssoToken.ExpiresIn),
            });
        }
        /// <summary>
        /// Initiates the asynchronous execution of the StartDeviceAuthorization operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the StartDeviceAuthorization operation on AmazonSSOOIDCClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndStartDeviceAuthorization
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/sso-oidc-2019-06-10/StartDeviceAuthorization">REST API Reference for StartDeviceAuthorization Operation</seealso>
        public virtual IAsyncResult BeginStartDeviceAuthorization(StartDeviceAuthorizationRequest request, AsyncCallback callback, object state)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = StartDeviceAuthorizationRequestMarshaller.Instance;
            options.ResponseUnmarshaller = StartDeviceAuthorizationResponseUnmarshaller.Instance;

            return(BeginInvoke(request, options, callback, state));
        }
        /// <summary>
        /// Initiates device authorization by requesting a pair of verification codes from the
        /// authorization service.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the StartDeviceAuthorization service method.</param>
        ///
        /// <returns>The response from the StartDeviceAuthorization service method, as returned by SSOOIDC.</returns>
        /// <exception cref="Amazon.SSOOIDC.Model.InternalServerException">
        /// Indicates that an error from the service occurred while trying to process a request.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.InvalidClientException">
        /// Indicates that the <code>clientId</code> or <code>clientSecret</code> in the request
        /// is invalid. For example, this can occur when a client sends an incorrect <code>clientId</code>
        /// or an expired <code>clientSecret</code>.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.InvalidRequestException">
        /// Indicates that something is wrong with the input to the request. For example, a required
        /// parameter might be missing or out of range.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.SlowDownException">
        /// Indicates that the client is making the request too frequently and is more than the
        /// service can handle.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.UnauthorizedClientException">
        /// Indicates that the client is not currently authorized to make the request. This can
        /// happen when a <code>clientId</code> is not issued for a public client.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/sso-oidc-2019-06-10/StartDeviceAuthorization">REST API Reference for StartDeviceAuthorization Operation</seealso>
        public virtual StartDeviceAuthorizationResponse StartDeviceAuthorization(StartDeviceAuthorizationRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = StartDeviceAuthorizationRequestMarshaller.Instance;
            options.ResponseUnmarshaller = StartDeviceAuthorizationResponseUnmarshaller.Instance;

            return(Invoke <StartDeviceAuthorizationResponse>(request, options));
        }
Beispiel #6
0
        /// <summary>
        /// Initiates device authorization by requesting a pair of verification codes from the
        /// authorization service.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the StartDeviceAuthorization service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the StartDeviceAuthorization service method, as returned by SSOOIDC.</returns>
        /// <exception cref="Amazon.SSOOIDC.Model.InternalServerException">
        /// Indicates that an error from the service occurred while trying to process a request.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.InvalidClientException">
        /// Indicates that the <code>clientId</code> or <code>clientSecret</code> in the request
        /// is invalid. For example, this can occur when a client sends an incorrect <code>clientId</code>
        /// or an expired <code>clientSecret</code>.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.InvalidRequestException">
        /// Indicates that something is wrong with the input to the request. For example, a required
        /// parameter might be missing or out of range.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.SlowDownException">
        /// Indicates that the client is making the request too frequently and is more than the
        /// service can handle.
        /// </exception>
        /// <exception cref="Amazon.SSOOIDC.Model.UnauthorizedClientException">
        /// Indicates that the client is not currently authorized to make the request. This can
        /// happen when a <code>clientId</code> is not issued for a public client.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/sso-oidc-2019-06-10/StartDeviceAuthorization">REST API Reference for StartDeviceAuthorization Operation</seealso>
        public virtual Task <StartDeviceAuthorizationResponse> StartDeviceAuthorizationAsync(StartDeviceAuthorizationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = StartDeviceAuthorizationRequestMarshaller.Instance;
            options.ResponseUnmarshaller = StartDeviceAuthorizationResponseUnmarshaller.Instance;

            return(InvokeAsync <StartDeviceAuthorizationResponse>(request, options, cancellationToken));
        }
 public void AssertStartDeviceAuthorizationRequest(StartDeviceAuthorizationRequest expectedRequest)
 {
     OidcClient.Verify(mock => mock.StartDeviceAuthorization(It.Is <StartDeviceAuthorizationRequest>(MatchesRequest(expectedRequest))), Times.Once);
 }