public async void RefreshToken(string username) { CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider); CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider); InitiateRefreshTokenAuthRequest ra = new InitiateRefreshTokenAuthRequest() { AuthFlowType = AuthFlowType.REFRESH_TOKEN }; AuthFlowResponse authResponse = await user.StartWithRefreshTokenAuthAsync(ra); if (authResponse.AuthenticationResult != null) { cognitoUserSession = new CognitoUserSession(authResponse.AuthenticationResult.IdToken, authResponse.AuthenticationResult.AccessToken, authResponse.AuthenticationResult.RefreshToken, DateTime.Now, DateTime.Now.AddHours(1)); } }
public async Task <RequestResult> AuthnicateUser(string username, string password) { RequestResult result = new RequestResult(); try { CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider); CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider); InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest() { Password = password }; AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false); if (authResponse.AuthenticationResult != null) { cognitoUserSession = new CognitoUserSession(authResponse.AuthenticationResult.IdToken, authResponse.AuthenticationResult.AccessToken, authResponse.AuthenticationResult.RefreshToken, DateTime.Now, DateTime.Now.AddHours(1)); //JwtSecurityTokenHandler jt = new JwtSecurityTokenHandler(); //if (!jt.CanReadToken(authResponse.AuthenticationResult.AccessToken)) //{ //} //JwtSecurityToken tokenS = jt.ReadToken(authResponse.AuthenticationResult.AccessToken) as JwtSecurityToken; //result.Id = tokenS.Id; //IEnumerable<Claim> cc = tokenS.Claims; //result.cc = cc; result.Status = true; result.Data = user; } else { result.Status = false; } } catch (Exception ex) { result.Status = false; result.Message = ex.Message; } return(result); }