private void OnLogIn(AccessToken accessToken, TaskCompletionSource <ICognitoAWSCredentials> promise) { ICognitoAWSCredentials credentials = _aws.CreateCognitoAWSCredentials(_identityPoolId, _region); credentials.AddLogin("graph.facebook.com", accessToken.TokenString); promise.SetResult(credentials); }
private void OnSignedUp(string deviceId, string devicePassword, TaskCompletionSource <ICognitoAWSCredentials> promise) { var userPool = new CognitoUserPool(_userPoolId, _clientId, _cipClient); var user = new CognitoUser(deviceId, userPool.ClientID, userPool, _cipClient); var srpRequest = new InitiateSrpAuthRequest(); srpRequest.Password = devicePassword; _logger.Log($"Authenticating for user {deviceId}"); user.StartWithSrpAuthAsync(srpRequest, srpResult => { if (srpResult.Exception != null) { if (srpResult.Exception is UserNotFoundException) { var signUpRequest = new SignUpRequest(); signUpRequest.Username = deviceId; signUpRequest.Password = devicePassword; signUpRequest.ClientId = _clientId; _logger.Log($"SignUp with new credentials for user {deviceId}"); _cipClient.SignUpAsync(signUpRequest, signUpResult => { if (signUpResult.Exception != null) { promise.SetException(signUpResult.Exception); return; } _logger.Log("SignUp success!"); if (signUpResult.Response != null) { _logger.Log("UserSub:" + signUpResult.Response.UserSub); } _preferences.SetValue(_DeviceIdKey, deviceId); _preferences.SetValue(_DevicePasswordKey, devicePassword); OnSignedUp(deviceId, devicePassword, promise); }); return; } promise.SetException(srpResult.Exception); return; } _logger.Log("Authentication success!"); ICognitoAWSCredentials credentials = user.GetCognitoAWSCredentials( _identityPoolId, RegionEndpoint.GetBySystemName(_region), _aws); promise.SetResult(credentials); }); }
/// <summary> /// Creates the CognitoAWSCredentials for accessing AWS resources. Should only be called with an authenticated user. /// </summary> /// <param name="identityPoolID">The poolID of the identity pool the user belongs to</param> /// <param name="identityPoolRegion">The region of the identity pool the user belongs to</param> /// <returns>Returns the CognitoAWSCredentials for the user to be able to access AWS resources</returns> public ICognitoAWSCredentials GetCognitoAWSCredentials(string identityPoolID, RegionEndpoint identityPoolRegion, IAWSSDK sdk) { EnsureUserAuthenticated(); string poolRegion = UserPool.PoolID.Substring(0, UserPool.PoolID.IndexOf("_")); string providerName = "cognito-idp." + poolRegion + ".amazonaws.com/" + UserPool.PoolID; ICognitoAWSCredentials credentials = sdk.CreateCognitoAWSCredentials(identityPoolID, identityPoolRegion.SystemName); credentials.Clear(); credentials.AddLogin(providerName, SessionTokens.IdToken); return(credentials); }
public void Login() { Debug.Log("DOING: Login"); _user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = "******" }, r => { if (r.Exception != null) { Debug.LogException(r.Exception); return; } if (r.Result.AuthenticationResult != null) { Debug.Log("r.Result.AuthenticationResult.AccessToken: " + r.Result.AuthenticationResult.AccessToken); Debug.Log("r.Result.AuthenticationResult.IdToken: " + r.Result.AuthenticationResult.IdToken); Debug.Log("r.Result.AuthenticationResult.TokenType: " + r.Result.AuthenticationResult.TokenType); ICognitoAWSCredentials credentials = _user.GetCognitoAWSCredentials(IdentityPoolId, RegionEndpoint.GetBySystemName(Region), _aws); credentials.GetCredentialsAsync(creds => { if (creds.Exception != null) { Debug.LogException(creds.Exception); return; } Debug.Log("creds.Response.AccessKey: " + creds.Response.AccessKey); Debug.Log("creds.Response.SecretKey: " + creds.Response.SecretKey); Debug.Log("creds.Response.Token: " + creds.Response.Token); }); } else { Debug.Log("r.Result.ChallengeName: " + r.Result.ChallengeName); } }); }
public JavaScriptLambdaClient(ICognitoAWSCredentials credentials, string region) { this.credentials = credentials; this.region = region; }
public JavaScriptCognitoIdentityProviderClient(ICognitoAWSCredentials credentials, string region) { this.credentials = credentials; this.region = region; }
public JavaScriptSimpleNotificationServiceClient(ICognitoAWSCredentials credentials, string region) { this.credentials = credentials; this.region = region; }
public JavaScriptMobileAnalyticsClient(ICognitoAWSCredentials credentials, string region) { this.credentials = credentials; this.region = region; }