public override void RefreshDatasetMetadataAsync(AmazonCognitoCallback callback, object state)
        {
            AmazonCognitoResult callbackResult = new AmazonCognitoResult(state);

            cognitoCredentials.GetCredentialsAsync(delegate(AmazonServiceResult getCredentialsResult) {
                if (getCredentialsResult.Exception != null)
                {
                    callbackResult.Exception = getCredentialsResult.Exception;
                    AmazonMainThreadDispatcher.ExecCallback(callback, callbackResult);
                    return;
                }
                remote.GetDatasetsAsync(delegate(AmazonCognitoResult result)
                {
                    if (result.Exception != null)
                    {
                        callbackResult.Exception = result.Exception;
                    }
                    else
                    {
                        GetDatasetsResponse response = result.Response as GetDatasetsResponse;
                        local.UpdateDatasetMetadata(GetIdentityId(), response.Datasets);
                        callbackResult.Response = response;
                    }
                    AmazonMainThreadDispatcher.ExecCallback(callback, callbackResult);
                }, state);
            }, null);
        }
Exemplo n.º 2
0
    // Called by Unity when the Gameobject is created
    void Start()
    {
        FindObjectOfType <UIManager>().SetTextBox("Setting up Client..");

        // Set up Mobile SDK
        UnityInitializer.AttachToGameObject(this.gameObject);
        AWSConfigs.AWSRegion  = MatchmakingClient.regionString;
        AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;

        // Get Cognito Identity and start Connecting to server once we have the identity
        CognitoAWSCredentials credentials = new CognitoAWSCredentials(
            MatchmakingClient.identityPoolID,
            MatchmakingClient.region
            );

        credentials.GetCredentialsAsync(
            (response) => {
            Debug.Log("Received CognitoCredentials: " + response.Response);
            cognitoCredentials = response.Response;

            // Start a coroutine for the connection process to keep UI updated while it's happening
            StartCoroutine(ConnectToServer());
        }
            );
    }
        void CognitoLogin(string facebookToken)
        {
            Debug.Log(facebookToken);
            string                cognitoPool   = "us-east-1:53dd5506-b8ba-4543-b883-c74c206c1f4d";
            RegionEndpoint        cognitoRegion = RegionEndpoint.USEast1;
            CognitoAWSCredentials credentials   = new CognitoAWSCredentials(cognitoPool, cognitoRegion);

            credentials.AddLogin("graph.facebook.com", facebookToken);
            credentials.GetCredentialsAsync(CognitoGetCredentialsCallback, null);
        }
Exemplo n.º 4
0
        public async Task <bool> getCredentials()
        {
            var credentials = new CognitoAWSCredentials(Statics.identityPoolID,
                                                        RegionEndpoint.EUWest2);

            var providername =
                $"cognito-idp.{RegionEndpoint.EUWest2.SystemName}.amazonaws.com/{Statics.poolID}";

            Console.WriteLine(providername);
            credentials.AddLogin(providername, Statics.id_token);

            var creds = await credentials.GetCredentialsAsync();

            Statics.creds       = creds;
            Statics.credentials = credentials;

            Console.WriteLine("log in id::" + credentials);
            Console.WriteLine(creds);

            return(true);
        }
    /// <summary>
    /// Retrieve an identity string from Cognito, using Facebook for
    /// authentication if possible.
    /// </summary>
    /// <param name="callback">Callback function, callback(error, identity).</param>
    public void GetIdentity()
    {
        loading = true;

        AmazonServiceCallback serviceCallback = delegate(AmazonServiceResult serviceResult)
        {
            loading = false;

            if (serviceResult.Exception != null)
            {
                myIdentity = "";
                Debug.LogError("Exception: " + serviceResult.Exception.Message);
            }
            else
            {
                myIdentity = credentials.IdentityProvider.GetCurrentIdentityId();
                Debug.Log(String.Format("[CognitoIdentityManager] Got identity '{0}'.", myIdentity));
            }
        };

        credentials.GetCredentialsAsync(serviceCallback, null);
    }
Exemplo n.º 6
0
        async void Run()
        {
            var cognitoIdp     = new AmazonCognitoIdentityProviderClient();
            var region         = ConfigurationManager.AppSettings["region"];
            var userPoolId     = ConfigurationManager.AppSettings["userPoolId"];
            var clientId       = ConfigurationManager.AppSettings["clientId"];
            var identityPoolId = ConfigurationManager.AppSettings["identityPoolId"];
            var username       = ConfigurationManager.AppSettings["username"];
            var password       = ConfigurationManager.AppSettings["password"];
            var apiId          = ConfigurationManager.AppSettings["apiId"];
            var stage          = ConfigurationManager.AppSettings["stage"];
            var method         = ConfigurationManager.AppSettings["method"];
            var path           = ConfigurationManager.AppSettings["path"];
            var querystring    = ConfigurationManager.AppSettings["querystring"];

            try
            {
                var request = new AdminInitiateAuthRequest
                {
                    AuthFlow       = AuthFlowType.ADMIN_NO_SRP_AUTH,
                    ClientId       = clientId,
                    UserPoolId     = userPoolId,
                    AuthParameters = { { "USERNAME", username }, { "PASSWORD", password } }
                };

                var response = await cognitoIdp.AdminInitiateAuthAsync(request);

                var idToken = response.AuthenticationResult.IdToken;

                var credentials = new CognitoAWSCredentials(identityPoolId, RegionEndpoint.GetBySystemName(region));
                var provider    = String.Format("cognito-idp.{0}.amazonaws.com/{1}", region, userPoolId);
                credentials.AddLogin(provider, idToken);

                var immutableCredentials = await credentials.GetCredentialsAsync();

                var endpoint = String.Format("https://{0}.execute-api.{1}.amazonaws.com/{2}/{3}", apiId, region, stage, path);
                if (!String.IsNullOrWhiteSpace(querystring))
                {
                    endpoint = endpoint + "?" + querystring;
                }
                var uri = new Uri(endpoint);

                var headers = new Dictionary <string, string>
                {
                    { AWS4SignerBase.X_Amz_Content_SHA256, AWS4SignerBase.EMPTY_BODY_SHA256 },
                    { "X-Amz-Security-Token", immutableCredentials.Token },
                    { "content-type", "application/json" }
                };

                var signer = new AWS4SignerForAuthorizationHeader
                {
                    EndpointUri = uri,
                    HttpMethod  = method,
                    Service     = "execute-api",
                    Region      = region
                };

                var authorization = signer.ComputeSignature(
                    headers,
                    querystring,
                    AWS4SignerBase.EMPTY_BODY_SHA256,
                    immutableCredentials.AccessKey,
                    immutableCredentials.SecretKey);

                headers.Add("Authorization", authorization);

                HttpHelpers.InvokeHttpRequest(uri, method, headers, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occurred.");
                Console.WriteLine(ex);
            }
        }
 /// <summary>
 /// Login to Cognito with the Facebook token
 /// </summary>
 /// <param name="facebookToken">Facebook token.</param>
 private void CognitoLogin()
 {
     Log("FB Cognito auth");
     credentials.AddLogin("graph.facebook.com", AccessToken.CurrentAccessToken.TokenString);
     credentials.GetCredentialsAsync(CognitoGetCredentialsCallback, null);
 }
Exemplo n.º 8
0
 void RefreshIdentity(string guestName)
 {
     Debug.Log("Cognito Identity: Refreshing Identity - " + guestName);
     m_credentials.GetCredentialsAsync((val) => { HandleGetIdentityIdCallback(val, guestName); }, null);
     Status = LoginStatus.Processing;
 }