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), }); }
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; } }