context: /*
   * Copyright 2014-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   *
   * Licensed under the AWS Mobile SDK for Unity Developer Preview License Agreement (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located in the "license" file accompanying this file.
   * See the License for the specific language governing permissions and limitations under the License.
   *
   */
  
  
  using System;
  using System.Threading;
  
  using Amazon.CognitoIdentity.Model;
  using Amazon.CognitoIdentity.Model.Internal.MarshallTransformations;
  using Amazon.Runtime;
  using Amazon.Runtime.Internal;
  using Amazon.Runtime.Internal.Auth;
  using Amazon.Runtime.Internal.Transform;
  using Amazon.Unity3D;
  
  namespace Amazon.CognitoIdentity
  {
      /// <summary>
      /// Implementation for accessing CognitoIdentity
      ///
      /// Amazon Cognito 
      /// <para>
      /// Amazon Cognito is a web service that delivers scoped temporary credentials to mobile
      /// devices and other untrusted environments. Amazon Cognito uniquely identifies a device
      /// and supplies the user with a consistent identity over the lifetime of an application.
      /// </para>
      ///  
      /// <para>
      /// Using Amazon Cognito, you can enable authentication with one or more third-party identity
      /// providers (Facebook, Google, or Login with Amazon), and you can also choose to support
      /// unauthenticated access from your app. Cognito delivers a unique identifier for each
      /// user and acts as an OpenID token provider trusted by AWS Security Token Service (STS)
      /// to access temporary, limited-privilege AWS credentials.
      /// </para>
      ///  
      /// <para>
      /// To provide end-user credentials, first make an unsigned call to <a>GetId</a>. If the
      /// end user is authenticated with one of the supported identity providers, set the <code>Logins</code>
      /// map with the identity provider token. <code>GetId</code> returns a unique identifier
      /// for the user.
      /// </para>
      ///  
      /// <para>
      /// Next, make an unsigned call to <a>GetCredentialsForIdentity</a>. This call expects
      /// the same <code>Logins</code> map as the <code>GetId</code> call, as well as the <code>IdentityID</code>
      /// originally returned by <code>GetId</code>. Assuming your identity pool has been configured
      /// via the <a>SetIdentityPoolRoles</a> operation, <code>GetCredentialsForIdentity</code>
      /// will return AWS credentials for your use. If your pool has not been configured with
      /// <code>SetIdentityPoolRoles</code>, or if you want to follow legacy flow, make an unsigned
      /// call to <a>GetOpenIdToken</a>, which returns the OpenID token necessary to call STS
      /// and retrieve AWS credentials. This call expects the same <code>Logins</code> map as
      /// the <code>GetId</code> call, as well as the <code>IdentityID</code> originally returned
      /// by <code>GetId</code>. The token returned by <code>GetOpenIdToken</code> can be passed
      /// to the STS operation <a href="http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html">AssumeRoleWithWebIdentity</a>
      /// to retrieve AWS credentials.
      /// </para>
      ///  
      /// <para>
      /// If you want to use Amazon Cognito in an Android, iOS, or Unity application, you will
      /// probably want to make API calls via the AWS Mobile SDK. To learn more, see the <a
      /// href="http://docs.aws.amazon.com/mobile/index.html">AWS Mobile SDK Developer Guide</a>.
      /// </para>
      /// </summary>
      public partial class AmazonCognitoIdentityClient : AmazonWebServiceClient, IAmazonCognitoIdentity
      {
          AWS4Signer signer = new AWS4Signer();
  
          #region Dispose
  
          protected override void Dispose(bool disposing)
          {
              base.Dispose(disposing);
          }
  
          #endregion
  
          #region Constructors
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with the CachingCognitoAWSCredentials loaded 
          /// from the AWSPrefab Editor variables along with the default RegionEndpoint(if any) of CognitoIdentity 
          /// </summary>
          public AmazonCognitoIdentityClient()
              : base(FallbackCredentialsFactory.GetCredentials(), new AmazonCognitoIdentityConfig(), AuthenticationTypes.User | AuthenticationTypes.Session) { }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with the CachingCognitoAWSCredentials loaded 
          /// from the AWSPrefab Editor variables
          /// </summary>
          /// <param name="region">The region to connect.</param>
          public AmazonCognitoIdentityClient(RegionEndpoint region)
              : base(FallbackCredentialsFactory.GetCredentials(), new AmazonCognitoIdentityConfig{RegionEndpoint = region}, AuthenticationTypes.User | AuthenticationTypes.Session) { }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with the CachingCognitoAWSCredentials loaded 
          /// from the AWSPrefab Editor variables
          /// </summary>
          /// <param name="config">The AmazonCognitoIdentityClient Configuration Object</param>
          public AmazonCognitoIdentityClient(AmazonCognitoIdentityConfig config)
              : base(FallbackCredentialsFactory.GetCredentials(), config, AuthenticationTypes.User | AuthenticationTypes.Session) { }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Credentials
          /// </summary>
          /// <param name="credentials">AWS Credentials</param>
          public AmazonCognitoIdentityClient(AWSCredentials credentials)
              : this(credentials, new AmazonCognitoIdentityConfig())
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Credentials
          /// </summary>
          /// <param name="credentials">AWS Credentials</param>
          /// <param name="region">The region to connect.</param>
          public AmazonCognitoIdentityClient(AWSCredentials credentials, RegionEndpoint region)
              : this(credentials, new AmazonCognitoIdentityConfig{RegionEndpoint = region})
          {
  
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Credentials and an
          /// AmazonCognitoIdentityClient Configuration object.
          /// </summary>
          /// <param name="credentials">AWS Credentials</param>
          /// <param name="clientConfig">The AmazonCognitoIdentityClient Configuration Object</param>
          public AmazonCognitoIdentityClient(AWSCredentials credentials, AmazonCognitoIdentityConfig clientConfig)
              : base(credentials, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Access Key ID and AWS Secret Key
          /// </summary>
          /// <param name="awsAccessKeyId">AWS Access Key ID</param>
          /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
          public AmazonCognitoIdentityClient(string awsAccessKeyId, string awsSecretAccessKey)
              : this(awsAccessKeyId, awsSecretAccessKey, new AmazonCognitoIdentityConfig())
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Access Key ID and AWS Secret Key
          /// </summary>
          /// <param name="awsAccessKeyId">AWS Access Key ID</param>
          /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
          /// <param name="region">The region to connect.</param>
          public AmazonCognitoIdentityClient(string awsAccessKeyId, string awsSecretAccessKey, RegionEndpoint region)
              : this(awsAccessKeyId, awsSecretAccessKey, new AmazonCognitoIdentityConfig() {RegionEndpoint=region})
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Access Key ID, AWS Secret Key and an
          /// AmazonCognitoIdentityClient Configuration object. 
          /// </summary>
          /// <param name="awsAccessKeyId">AWS Access Key ID</param>
          /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
          /// <param name="clientConfig">The AmazonCognitoIdentityClient Configuration Object</param>
          public AmazonCognitoIdentityClient(string awsAccessKeyId, string awsSecretAccessKey, AmazonCognitoIdentityConfig clientConfig)
              : base(awsAccessKeyId, awsSecretAccessKey, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Access Key ID and AWS Secret Key
          /// </summary>
          /// <param name="awsAccessKeyId">AWS Access Key ID</param>
          /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
          /// <param name="awsSessionToken">AWS Session Token</param>
          public AmazonCognitoIdentityClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken)
              : this(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, new AmazonCognitoIdentityConfig())
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Access Key ID and AWS Secret Key
          /// </summary>
          /// <param name="awsAccessKeyId">AWS Access Key ID</param>
          /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
          /// <param name="awsSessionToken">AWS Session Token</param>
          /// <param name="region">The region to connect.</param>
          public AmazonCognitoIdentityClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, RegionEndpoint region)
              : this(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, new AmazonCognitoIdentityConfig{RegionEndpoint = region})
          {
          }
  
          /// <summary>
          /// Constructs AmazonCognitoIdentityClient with AWS Access Key ID, AWS Secret Key and an
          /// AmazonCognitoIdentityClient Configuration object. 
          /// </summary>
          /// <param name="awsAccessKeyId">AWS Access Key ID</param>
          /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
          /// <param name="awsSessionToken">AWS Session Token</param>
          /// <param name="clientConfig">The AmazonCognitoIdentityClient Configuration Object</param>
          public AmazonCognitoIdentityClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonCognitoIdentityConfig clientConfig)
              : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
          {
          }
  
          #endregion
  
          
          #region  CreateIdentityPool
  
  
          /// <summary>
          /// Initiates the asynchronous execution of the CreateIdentityPool operation.
          /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
          /// </summary>
          /// <param name="request">Container for the necessary parameters to execute the CreateIdentityPool operation.</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>void</returns>
          public void CreateIdentityPoolAsync(CreateIdentityPoolRequest request, AmazonServiceCallback callback, object state)
          {
              if (!AmazonInitializer.IsInitialized)
                  throw new Exception("AWSPrefab is not added to the scene");
  
              ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
              {
  
gt:                 var marshaller = new CreateIdentityPoolRequestMarshaller();