How to pass Cognito token to Amazon API Gateway?

前端 未结 1 1345
孤街浪徒
孤街浪徒 2020-12-16 17:17

I\'m developing web app based on Amazon API Gateway. Now I created Facebook login and successfully logged into website. but when I call another API, everything gone. I think

相关标签:
1条回答
  • 2020-12-16 17:31

    You are using the "Basic Authflow" from cognito identity, which means you will need to get credentials for your users by calling STS's "AssumeRoleWithWebIdentity". Here is some documentation to help: http://docs.aws.amazon.com/cognito/devguide/identity/concepts/authentication-flow/

    Once you have credentials, you can instantiate the API Gateway Client:

    var client = apigClientFactory.newClient({ 
        accessKey: ACCESS_KEY, 
        secretKey: SECRET_KEY, 
        sessionToken: SESSION_TOKEN });
    

    The keys and tokens come from the result of the "AssumeRoleWithWebIdentity" call.

    If you have configured your IAM roles, and Authorizations correctly you should be able to access your API.

    Here is the documentation describing how to configure the roles & authorization: http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html#how-to-method-settings-callers-console

    Also, here is how to enable CORS - http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

    0 讨论(0)
提交回复
热议问题