【问题标题】:Amazon cognito unauthenticated flow from java来自java的Amazon cognito未经身份验证的流
【发布时间】:2021-09-30 14:04:40
【问题描述】:

我正在尝试从 Java 代码中获取未经授权的认知令牌。代码如下:

import com.amazonaws.services.cognitoidentity.AmazonCognitoIdentity;
import com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClientBuilder;
import com.amazonaws.services.cognitoidentity.model.GetCredentialsForIdentityRequest;
import com.amazonaws.services.cognitoidentity.model.GetIdRequest;
import com.amazonaws.services.cognitoidentity.model.GetIdResult;
import com.amazonaws.services.cognitoidentity.model.GetOpenIdTokenRequest;

public class unAuthorizedToken {
   public static void main(String args[]){
     AmazonCognitoIdentity identity =  AmazonCognitoIdentityClientBuilder.standard().withRegion("us-east-1").build();
    GetIdResult getId = identity.getId(new GetIdRequest().withIdentityPoolId("us-east-1:8xxxxxx-xxxx-xxxx-bxxx-5xxxxxxxxxxx"));

  //// obtain identity id and token to return to your client
    String identityId = getId.getIdentityId();
    System.out.println("IdentityId =" + identityId);
    GetOpenIdTokenRequest req = new GetOpenIdTokenRequest().withIdentityId(identityId);
    String token = identity.getOpenIdToken(req).getToken();
    System.out.println("Token =" + token);
}
}

未经身份验证的 cognito 令牌流正在使用 javascript。但是使用Java我得到了identityId,但是在获取令牌时,它要求我在这一行使用增强流: String token = identity.getOpenIdToken(req).getToken(); 异常:线程“主”com.amazonaws.services.cognitoidentity.model.InvalidParameterException 中的异常:未启用基本(经典)流,请使用增强流。 (服务:AmazonCognitoIdentity;状态代码:400;错误代码:InvalidParameterException;请求 ID:78a20c92-c0b0-4393-b972-8fa69765d7c1;代理:null) 什么是增强流量?这是否意味着不允许从 java 进行未经身份验证的访问?请帮我调试这段代码。

还想了解 com.amazonaws.services.* 和 software.amazon.awssdk.* 库之间的区别?

【问题讨论】:

    标签: java amazon-web-services aws-sdk amazon-cognito


    【解决方案1】:

    好的。根据此链接:不需要https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flow.html tokenid。我们可以通过身份ID进行身份验证

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-25
      • 2016-01-17
      • 1970-01-01
      • 2017-03-25
      • 2019-01-29
      • 2014-09-26
      • 2018-01-07
      • 1970-01-01
      相关资源
      最近更新 更多