Exemple #1
0
        public static async Task <GetSsoTokenResponse> GetSsoTokenAsync(IAmazonSSOOIDC client, GetSsoTokenRequest request, IGetSsoTokenContext context)
        {
            var registerClientRequest = new RegisterClientRequest()
            {
                ClientName = request.ClientName,
                ClientType = request.ClientType,
            };

            InternalSDKUtils.ApplyValues(registerClientRequest, request.AdditionalProperties);

            var registerClientResponse = await client.RegisterClientAsync(registerClientRequest).ConfigureAwait(false);


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

            InternalSDKUtils.ApplyValues(startDeviceAuthorizationRequest, request.AdditionalProperties);

            var startDeviceAuthorizationResponse =
                await client.StartDeviceAuthorizationAsync(startDeviceAuthorizationRequest).ConfigureAwait(false);


            // 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 = await PollForSsoTokenAsync(client,
                                                      createTokenRequest,
                                                      startDeviceAuthorizationResponse.Interval,
                                                      deviceCodeExpiration,
                                                      context).ConfigureAwait(false);

            return(new GetSsoTokenResponse()
            {
                AccessToken = ssoToken.AccessToken,
                ExpiresAt = DateTime.UtcNow.AddSeconds(ssoToken.ExpiresIn),
            });
        }
Exemple #2
0
 private Amazon.SSOOIDC.Model.RegisterClientResponse CallAWSServiceOperation(IAmazonSSOOIDC client, Amazon.SSOOIDC.Model.RegisterClientRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Single Sign-On OIDC", "RegisterClient");
     try
     {
         #if DESKTOP
         return(client.RegisterClient(request));
         #elif CORECLR
         return(client.RegisterClientAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }