简体   繁体   English

Amazon Cognito,自定义OpenID提供程序,“无效的登录令牌”错误

[英]Amazon Cognito, custom OpenID provider, “Invalid login token” error

I'm attempting to use Cognito with custom OpenID provider to get access to AWS services in my iOS app. 我正在尝试将Cognito与自定义OpenID提供程序一起使用,以访问我的iOS应用中的AWS服务。 As a custom OpenID provider I'm using our WP server with WP OAuth Server plugin. 作为自定义OpenID提供程序,我正在将我们的WP服务器与WP OAuth Server插件一起使用。 I created the identity provider from IAM Console with success (checked the thumbprint and it was correct). 我成功地从IAM控制台创建了身份提供程序(检查了指纹并正确)。 After that I created the identity pool with default roles and selected previously created provider in section "Authentication providers" -> OpenID tab. 之后,我使用默认角色创建了身份池,并在“身份验证提供程序”->“ OpenID”选项卡部分中选择了先前创建的提供程序。 And now in iOS app I'm trying to get the identityId with such code: 现在,在iOS应用程序中,我尝试使用以下代码获取identityId:

AWSCognitoCredentialsProvider *credentialsProvider =
    [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                               identityPoolId:poolId];
NSString *domain = @"my.dev.somename.com";
NSString *accessToken = <correct and actual oauth access token>;
credentialsProvider.logins = @{domain: accessToken};

AWSServiceConfiguration *configuration =
        [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
                                    credentialsProvider:credentialsProvider];

    [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

[[credentialsProvider getIdentityId] continueWithBlock:^id(AWSTask *task) {
        if (task.error) {
            NSLog(@"Error: %@", task.error.localizedDescription);
        }
        else {
            NSLog(@"identityID: %@", task.result);
        }
        return nil;
    }];

And every time I have "GetId failed. ... Invalid login token." 并且每次我遇到“ GetId失败。...无效的登录令牌”。 error (NotAuthorizedException). 错误(NotAuthorizedException)。 At the same time the access token is valid and not expired because I can use it to communicate with the server. 同时,访问令牌有效且未过期,因为我可以使用它与服务器进行通信。 The audience used during provider creation and poolId used in the code are correct for sure. 确保在提供程序创建期间使用的受众和代码中使用的poolId是正确的。

I'm not sure if that may help but need to mention that our server supports login with Facebook so just for tests I've added Facebook as an authenticated provider to the identity pool and it worked: I was able to get identityId in that way. 我不确定这是否有帮助,但需要提及我们的服务器支持使用Facebook登录,因此仅出于测试目的,我已将Facebook作为身份验证提供者添加到身份池中,并且它起作用了:我能够以这种方式获取identityId 。

Can anybody help with that? 有人可以帮忙吗?

Update: 更新:

The anwer from Scott is correct. 斯科特的回答是正确的。 The only problem here - there is no way to request OpenID token from the WP OAuth Server plugin (at least for version 3.1.5 I'm using). 这里唯一的问题-无法从WP OAuth Server插件请求OpenID令牌(至少对于我正在使用的3.1.5版本)。 It seems that the plugin supports only 3-legged authorization flow and we have 2-legged here. 看来该插件仅支持3条腿授权流,此处我们只有2条腿。 So I ended up with my custom WP plugin that uses "Developer Authenticated Identities Authflow" (see docs ) and custom developer authenticated provider ( code example ). 因此,我最终获得了使用“开发人员身份验证身份Authflow”(请参阅docs )和开发人员身份验证提供程序( 代码示例 )的自定义WP插件。 Hope that'll help somebody. 希望对您有所帮助。

Make sure that you're using a grant type that returns a valid OpenID Connect Token (the WP OAuth Server looks like it supports different tokens/grant types). 确保您使用的授权类型返回有效的OpenID Connect令牌(WP OAuth服务器看起来像它支持其他令牌/授权类型)。 You can use jwt.io to decode the token issued by your backend. 您可以使用jwt.io解码后端发出的令牌。 Validate the following about the token: 验证有关令牌的以下内容:

  1. The iss parameter must match the key used in the logins map ( eg login.provider.com ). iss参数必须与登录映射中使用的键匹配(例如,login.provider.com)。
  2. The signature must be valid. 签名必须有效。 The signature must be verifiable via an RSA public key. 签名必须可以通过RSA公钥进行验证。
  3. The fingerprint of the certificate hosting the public key matches what's configured on your OpenId Connect Provider. 承载公钥的证书的指纹与您的OpenId Connect Provider上配置的指纹匹配。
  4. If the azp parameter is present, check this value against listed client IDs in your OpenId Connect provider. 如果存在azp参数,请对照OpenId Connect提供程序中列出的客户端ID检查此值。
  5. If the azp parameter is not present, check the aud parameter against listed client IDs in your OpenId Connect provider. 如果azp参数不存在,请对照OpenId Connect提供程序中列出的客户端ID检查aud参数。

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

相关问题 使用自定义令牌(ERROR_INVALID_CUSTOM_TOKEN)的LinkedIn登录 - LinkedIn login with custom token ( ERROR_INVALID_CUSTOM_TOKEN ) 简单的Amazon Cognito注册和登录 - Simple Amazon Cognito Registration and Login Amazon Web Services:错误-请求中包含的安全令牌无效 - Amazon Web Services : Error - The security token included in the request is invalid Amazon Cognito可以替代“使用Amazon登录” SDK吗? - Can Amazon Cognito be a substitute for the Login-With-Amazon SDK? Facebook iOS SDK 登录错误(无效范围:public_profile、openid。) - Facebook iOS SDK login error (Invalid Scopes: public_profile, openid.) 错误:令牌无效。 尝试在Firebase上使用电子邮件/密码功能登录 - Error: invalid token. Trying to login with email/pw function on Firebase iOS Amazon Cognito登录错误InvalidParameterException - iOS Amazon Cognito Sign-In Error InvalidParameterException 将DynamoDB与Cognito一起使用:令牌不是来自此身份池的受支持提供商 - Using DynamoDB With Cognito: Token is not from a supported provider of this identity pool Amazon Cognito-重置导入用户的密码后无法登录 - Amazon Cognito - Unable to login after reset password for imported user 将 Amazon Cognito 与社交登录集成 - Apple Touch Id - Integration Amazon Cognito with Social Login - Apple Touch Id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM