示例#1
0
        private async Task <RespondToAuthChallengeResponse> VerifyChallenge(string username, string session, string accountId)
        {
            var provider = new AmazonCognitoIdentityProviderClient(RegionEndpoint.USEast2);

            try
            {
                var challengeRequest = new RespondToAuthChallengeRequest
                {
                    Session            = session,
                    ChallengeName      = "CUSTOM_CHALLENGE",
                    ClientId           = CLIENTAPP_ID,
                    ChallengeResponses = new Dictionary <string, string>()
                    {
                        { "ANSWER", accountId },
                        { "USERNAME", username }
                    }
                };

                return(await provider.RespondToAuthChallengeAsync(challengeRequest));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(null);
        }
示例#2
0
        public AuthenticationResult ChallengePassword(ResetPasswordQueryParams resetPasswordQueryParams)
        {
            RespondToAuthChallengeRequest authChallengeRequest = new RespondToAuthChallengeRequest
            {
                ChallengeName      = ChallengeNameType.NEW_PASSWORD_REQUIRED,
                ChallengeResponses = new Dictionary <string, string>
                {
                    { "NEW_PASSWORD", resetPasswordQueryParams.Password },
                    { "USERNAME", resetPasswordQueryParams.Email }
                },
                ClientId = _connectionInfo.ClientId,
                Session  = resetPasswordQueryParams.Session
            };
            var authResult = new AuthenticationResult();

            try
            {
                var authResp = _provider.RespondToAuthChallengeAsync(authChallengeRequest).Result;
                authResult.AccessToken  = authResp.AuthenticationResult.AccessToken;
                authResult.IdToken      = authResp.AuthenticationResult.IdToken;
                authResult.RefreshToken = authResp.AuthenticationResult.RefreshToken;
                authResult.TokenType    = authResp.AuthenticationResult.TokenType;
                authResult.ExpiresIn    = authResp.AuthenticationResult.ExpiresIn;
                authResult.Success      = true;
            }
            catch (Exception e)
            {
                LoggingHandler.LogError(e.Message);
                LoggingHandler.LogError(e.StackTrace);
                throw;
            }
            return(authResult);
        }