简体   繁体   English

是否可以使用访问令牌访问 AWS Cognito API?

[英]Is it possible to access AWS Cognito API with access token?

I have a simple application consisting of two modules - OAuth2 client (Spring Cloud Gateway) and OAuth2 resource.我有一个由两个模块组成的简单应用程序 - OAuth2 客户端(Spring Cloud Gateway)和 OAuth2 资源。 I use AWS Cognito as an identity provider.我使用 AWS Cognito 作为身份提供商。 Some users with specific roles should be able to create/update/delete other Cognito users.一些具有特定角色的用户应该能够创建/更新/删除其他 Cognito 用户。

I'm going to use aws-java-sdk-cognitoidp library for integration with AWS Cognito API, but I need to make this calls as a current logged-in user, to be able to check user's groups and IAM roles.我将使用aws-java-sdk-cognitoidp库与 AWS Cognito API 集成,但我需要以当前登录用户的身份进行此调用,以便能够检查用户的组和 IAM 角色。 Because users from different groups should have different privileges.因为不同组的用户应该有不同的权限。

I found AWSSessionCredentialsProvider that seems suitable for this task, but there is no implementation.我发现AWSSessionCredentialsProvider似乎适合这项任务,但没有实施。

I implemented this provider to get access token from the SecurityContext .我实现了此提供程序以从SecurityContext获取访问令牌。 When I call the API I get an error:当我调用 API 时出现错误:

The security token included in the request is invalid请求中包含的安全令牌无效

Is it possible to use user's access token as a credentials for AWSCognitoIdentityProvider ?是否可以使用用户的访问令牌作为AWSCognitoIdentityProvider的凭证?

I used to have app to login with given user with his credentials -我曾经让应用程序使用给定用户的凭据登录 -

AWSCognitoIdentityProvider cognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder
                .standard()
                .withCredentials(new AWSStaticCredentialsProvider(getSDKCredentials()))
                .withRegion(Regions.fromName(getAwsRegion()))
                .build();

    Map<String,String> params =new HashMap<>();
        params.put("USERNAME", userName);
        params.put("PASSWORD", passCode);

    AdminInitiateAuthRequest initialRequest=new AdminInitiateAuthRequest()
            .withAuthFlow(AuthFlowType.ADMIN_NO_SRP_AUTH)
            .withAuthParameters(params)
            .withClientId(getClientId())
            .withUserPoolId(getUserPoolId());

    AdminInitiateAuthResult response = cognitoIdentityProvider.adminInitiateAuth(initialRequest);

this will return your response where you have session.这将在您拥有 session 的地方返回您的响应。 check if it helps-检查它是否有帮助-

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

相关问题 AWS Cognito - 访问和刷新令牌 - AWS Cognito - Access and refresh token AWS Cognito - 是否可以在使用 google in 从 aws cognito 登录时获取 google 访问令牌并使用 aws 访问令牌刷新 - AWS cognito - Is it possible to get google access token and refresh using aws access token when sign in using google in from aws cognito 验证 AWS Cognito JWT 令牌(访问令牌) - Validate AWS Cognito JWT Token (Access token) AWS API 网关授权器适用于 Cognito HostedUI,但不适用于 amazon-cognito-identity-js 中的 access_token - AWS API Gateway Authorizer works with Cognito HostedUI but not with access_token from amazon-cognito-identity-js 在 AWS Cognito 和 Lambda 中获取 Facebook 访问令牌 - Get Facebook access token in AWS Cognito and Lambda AWS Cognito一次性使用访问令牌 - AWS Cognito single use access token 手动设置 AWS Cognito 访问令牌超时 - Set AWS Cognito access token timeout manually 如何为AWS Cognito用户生成访问令牌? - How to generate access token for an AWS Cognito user? 如何在NodeJS上验证AWS Cognito访问令牌 - How to verify AWS Cognito Access Token on NodeJS 是否可以使用 aws cognito google oauth access_token 通过 boto3 获取临时凭证? - Is it possible to get temporary credentials via boto3 with aws cognito google oauth access_token?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM