private void Init(string authProvider, string accessToken) { if (string.IsNullOrEmpty(IDENTITY_POOL_ID)) { throw new NotSupportedException("Identity Pool ID is not set"); } //Create a Credentials provider that uses Cognito Identity credentials = new CognitoAWSCredentials(IDENTITY_POOL_ID, ENDPOINT); myIdentity = credentials.GetIdentityId(); credentials.IdentityChangedEvent += (object sender, Amazon.CognitoIdentity.CognitoAWSCredentials.IdentityChangedArgs e) => { Debug.Log("Identity Changed (old: '" + e.OldIdentityId + "', new: '" + e.NewIdentityId + "')"); myIdentity = e.NewIdentityId; }; //If fbAccesToken is set, we can use Cognito's authenticated identities if (accessToken != null) { credentials.AddLogin(authProvider, accessToken); } loggedIn = true; UpdateIdentity(); }
// Called when Start game button is clicked void StartGame() { if (!this.gameStartRequested) { this.startGameButton.gameObject.SetActive(false); this.gameStartRequested = true; FindObjectOfType <UIManager>().SetTextBox("Setting up Client.."); // Get the Region enum from the string value this.region = Amazon.RegionEndpoint.GetBySystemName(regionString); Debug.Log("My Region endpoint: " + this.region); // Check if we have stored an identity and request credentials for that existing identity Client.cognitoID = PlayerPrefs.GetString("CognitoID", null); if (Client.cognitoID != null && Client.cognitoID != "") { Debug.Log("Requesting credentials for existing identity: " + Client.cognitoID); var response = Task.Run(() => GetCredentialsForExistingIdentity(Client.cognitoID)); response.Wait(5000); Client.cognitoID = response.Result.IdentityId; Client.cognitoCredentials = new Amazon.Runtime.ImmutableCredentials(response.Result.Credentials.AccessKeyId, response.Result.Credentials.SecretKey, response.Result.Credentials.SessionToken); } // Else get a new identity else { Debug.Log("Requesting a new playeridentity as none stored yet."); CognitoAWSCredentials credentials = new CognitoAWSCredentials( this.identityPoolID, this.region); Client.cognitoCredentials = credentials.GetCredentials(); Client.cognitoID = credentials.GetIdentityId(); Debug.Log("Got Cognito ID: " + credentials.GetIdentityId()); // Store to player prefs and save for future games PlayerPrefs.SetString("CognitoID", Client.cognitoID); PlayerPrefs.Save(); } // Get latencies to regions this.MeasureLatencies(); // Connect to the server now that we have our identity, credendtials and latencies StartCoroutine(ConnectToServer()); } }
public void AuthenticatedCredentialsTest() { CognitoAWSCredentials authCred = AuthCredentials; string identityId = authCred.GetIdentityId(); Utils.AssertStringIsNotNullOrEmpty(identityId); ImmutableCredentials cred = authCred.GetCredentials(); Utils.AssertFalse(cred == null); }
//[TestMethod] //[TestCategory("SyncManager")] public void AuthenticatedCredentialsTest() { CognitoAWSCredentials authCred = AuthCredentials; string identityId = authCred.GetIdentityId(); Assert.IsTrue(!string.IsNullOrEmpty(identityId)); ImmutableCredentials cred = authCred.GetCredentials(); Assert.IsNotNull(cred); }
private void UploadUserData(string provider) { Debug.Log("Uploading user data to DynamoDB"); Users myUser = new Users { uid = awsCredentials.GetIdentityId(), name = playerInfo.Get("name"), providerId = playerInfo.Get("uid"), provider = provider, GameSessionIds = new List <string> { }, GameSessions = new List <Dictionary <string, string> > { }, Strategies = new List <Dictionary <string, int> > { }, gamesPlayed = 0, gamesWon = 0, gamesLost = 0, level = "NOVICE", levelPoints = 0, tickets = 2, imageUrl = null }; myUser.Strategies.Add(StrategyManagerScript.randomStrategyGenerator()); dbContext.SaveAsync(myUser, (result) => { if (result.Exception == null) { Debug.Log("Data uploaded to DynamoDB"); curUserData = myUser; playerInfo.SynchronizeOnConnectivity(); } else { Debug.Log(result.Exception.Message); Debug.Log(result.Exception.InnerException); Debug.Log(result.Exception); } }); }
private string GetCurrentIdentityId() { return(cognitoCredentials.GetIdentityId()); }