【问题标题】:AWS cognito does not generate tokens when run from a serverlet从 servlet 运行时,AWS cognito 不会生成令牌
【发布时间】:2015-03-04 09:06:39
【问题描述】:

我正在尝试让 amazon cognito 工作。如果我运行代码从独立的 java 程序生成登录令牌,它就可以工作。

public class cognito extends HttpServlet
{


public static void main(String[] args) throws Exception {

AWSCredentials credentials = new BasicAWSCredentials("*******", "********");

AmazonCognitoIdentityClient client =
new AmazonCognitoIdentityClient(credentials);
client.setRegion(Region.getRegion(Regions.EU_WEST_1)); 
GetOpenIdTokenForDeveloperIdentityRequest tokenRequest =
new GetOpenIdTokenForDeveloperIdentityRequest();
tokenRequest.setIdentityPoolId("*************");
HashMap<String, String> map = new HashMap<String, String>();

//Key -> Developer Provider Name used when creating the identity pool
//Value -> Unique identifier of the user in your <u>backend</u>
map.put("test", "AmazonCognitoIdentity");

//Duration of the generated OpenID Connect Token
tokenRequest.setLogins(map);
tokenRequest.setTokenDuration(1000l);

GetOpenIdTokenForDeveloperIdentityResult result = client
.getOpenIdTokenForDeveloperIdentity(tokenRequest);
String identityId = result.getIdentityId();
String token = result.getToken();

System.out.println("id = " + identityId + "  token = " + token);


} 

}

但是,当我从 Redhat linux 服务器上的 servlet 运行此代码时,它总是超时。 任何建议都会有所帮助

【问题讨论】:

  • 你能粘贴真正的错误信息吗?

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


【解决方案1】:

map.put("test", "AmazonCognitoIdentity");

您确定您的开发者提供商名称是“test”吗?

您可以在您的 cognito 身份池编辑页面中看到它。 而“AmazonCognitoIdentity”应该是您自己的唯一用户 ID。

【讨论】:

    【解决方案2】:

    如果没有实际的例外,很难说出确切的问题是什么。可能是在您的 servlet 引擎中运行的其他东西正在设置比从命令行运行时的默认值更激进的套接字超时。您可能希望使用使用此类 http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html 的方法显式设置连接和套接字超时,并将其传递给身份客户端构造函数。

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2021-04-10
      • 2023-03-25
      • 2018-08-10
      • 1970-01-01
      • 2022-01-02
      • 2015-09-19
      • 1970-01-01
      • 2020-03-19
      相关资源
      最近更新 更多