小编Law*_*ule的帖子

AWS Cognito RefreshToken API 始终显示“SecretHash 与客户端不匹配”

我创建了一个 AWS Cognito 用户池并添加了一个带有秘密的 APPClient。当我使用DotNet SDK进行注册、登录、cofirmSignup、注销时,这些API都是成功的。但是,当我尝试通过刷新令牌刷新 accessToken 时,我总是遇到异常“SecretHash 与客户端不匹配:xxxxxx(应用程序客户端 ID)”。有人可以帮忙吗?我的代码如下:

    var userPool = new CognitoUserPool(_cognitoSecret.CognitoUserPoolId, _cognitoSecret.CognitoAppClientId, _awsCognitoClient, appClientSecret);
    var cognitoUser = new CognitoUser(request.Username,
        _cognitoSecret.CognitoAppClientId, userPool, _awsCognitoClient, appClientSecret);

    cognitoUser.SessionTokens = new CognitoUserSession(null, null, request.RefreshToken, DateTime.UtcNow, DateTime.UtcNow.AddSeconds(Constants.DefaultTokenExpirationTime));

    var authRequest = new InitiateRefreshTokenAuthRequest
    {

        AuthFlowType = AuthFlowType.REFRESH_TOKEN_AUTH    // to refresh access token and id token
    };

    var response = await cognitoUser.StartWithRefreshTokenAuthAsync(authRequest);
Run Code Online (Sandbox Code Playgroud)

我也尝试了另一种方法,但得到了同样的例外:

    var refreshTokenRequest = new InitiateAuthRequest
    {
        ClientId = _cognitoSecret.CognitoAppClientId,
        AuthFlow = AuthFlowType.REFRESH_TOKEN_AUTH
    };

    refreshTokenRequest.AuthParameters.Add("REFRESH_TOKEN", request.RefreshToken);
    if (!string.IsNullOrWhiteSpace(_cognitoSecret.CognitoAppClientId) && !string.IsNullOrWhiteSpace(_cognitoSecret.CognitoAppClientSecret))
    {
        var …
Run Code Online (Sandbox Code Playgroud)

.net sdk amazon-web-services amazon-cognito

8
推荐指数
1
解决办法
2198
查看次数

标签 统计

.net ×1

amazon-cognito ×1

amazon-web-services ×1

sdk ×1