iOS AWS API 网关:此身份池不支持未经身份验证的访问


//setup service config
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:CognitoIdentityUserPoolRegion credentialsProvider:nil];

//create a pool

AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:CognitoIdentityUserPoolAppClientId  clientSecret:nil poolId:CognitoIdentityUserPoolId];
[AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration:serviceConfiguration userPoolConfiguration:configuration forKey:@"UserPool"];
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
pool.delegate = self;
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion
                              identityPoolId:CognitoIdentityPoolId];
AWSServiceConfiguration *configuration1 = [[AWSServiceConfiguration alloc] initWithRegion:CognitoIdentityUserPoolRegion
    credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration1;

以上是我在appdelegate中的代码。 我正在使用 AWS 文档"CognitoYourUserPool"中的示例登录。 并尝试使用适用于iOS的生成SDK调用API。

API_Client *apiInstance = [API_Client defaultClient];
[apiInstance setAPIKey:@"xxxxxxxxxxxxxxxxxxxxxx"];        
[[apiInstance presetTypeGet] continueWithBlock:^id _Nullable(AWSTask * _Nonnull t) {
NSLog(@"error: %@",t.error);
NSLog(@"result: %@",t.result);
return nil;
}];

登录后我确实调用了API,但这是错误的。 我现在不知道为什么。 请帮助我。如果您需要更多信息,请询问。 谢谢。

试试这个:

AWSCognitoIdentityUserPoolConfiguration *configuration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:CognitoIdentityUserPoolAppClientId  clientSecret:nil poolId:CognitoIdentityUserPoolId];
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion identityPoolId:CognitoIdentityPoolId];
AWSServiceConfiguration *configuration1 = [[AWSServiceConfiguration alloc] initWithRegion:CognitoIdentityUserPoolRegion credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration1;
[AWSCognitoIdentityUserPool registerCognitoIdentityUserPoolWithConfiguration: configuration1 userPoolConfiguration:configuration forKey:@"UserPool"];
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
pool.delegate = self;

两天后,我想通了。

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoIdentityUserPoolRegion
                              identityPoolId:CognitoIdentityPoolId identityProviderManager:pool];

需要设置 identityProviderManager。 谢谢。

相关内容

  • 没有找到相关文章

最新更新