简体   繁体   English

来自 Java 的 Amazon Cognito 未经身份验证的流

[英]Amazon cognito unauthenticated flow from java

I am trying to get an unauthorized cognito token from a java code.我正在尝试从 Java 代码中获取未经授权的认知令牌。 Here is the code:这是代码:

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);
}
}

The unauthenticated cognito token flow is working with javascript.未经身份验证的认知令牌流正在使用 javascript。 but with Java I am getting the identityId but while getting the token, it is asking me to use enhanced flow at this line: String token = identity.getOpenIdToken(req).getToken();但是使用 Java 我得到了 identityId 但在获取令牌时,它要求我在这一行使用增强的流程: String token = identity.getOpenIdToken(req).getToken(); Exception: Exception in thread "main" com.amazonaws.services.cognitoidentity.model.InvalidParameterException: Basic (classic) flow is not enabled, please use enhanced flow.异常:线程“main”com.amazonaws.services.cognitoidentity.model.InvalidParameterException 中的异常:未启用基本(经典)流,请使用增强流。 (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: InvalidParameterException; Request ID: 78a20c92-c0b0-4393-b972-8fa69765d7c1; Proxy: null) What is enhanced flow? (服务:AmazonCognitoIdentity;状态代码:400;错误代码:InvalidParameterException;请求 ID:78a20c92-c0b0-4393-b972-8fa69765d7c1;代理:null)什么是增强流? does it mean unauthenticated access is not allowed from java?这是否意味着 Java 不允许未经身份验证的访问? Please help me debug this code.请帮我调试这段代码。

Also wanted to understand what is the difference between: com.amazonaws.services.* and software.amazon.awssdk.* libraries?还想了解:com.amazonaws.services.* 和 software.amazon.awssdk.* 库之间的区别是什么?

Ok.行。 according to this link: https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flow.html tokenid is not needed.根据此链接:不需要https://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flow.html tokenid。 we can pass identity id for authentication我们可以通过身份 ID 进行身份验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM