0

我正试图让亚马逊认知工作。如果我运行代码以从独立的 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 运行此代码时,它总是超时。任何建议都会有所帮助

4

2 回答 2

0

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

于 2015-01-08T23:49:45.517 回答
0

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

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

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

于 2015-01-07T11:29:49.277 回答