简体   繁体   English

在没有 AWS-SDK 的情况下使用 Cognito JavaScript SDK

[英]Using Cognito JavaScript SDK without AWS-SDK

I'm using the Amazon's JavaScript AWS-SDK to set the region and credentials for me to use Cognito on my client application.我正在使用 Amazon 的 JavaScript AWS-SDK设置区域和凭证,以便在我的客户端应用程序上使用 Cognito。 The problem is that the AWS-SDK is huge!问题是 AWS-SDK 太大了! Is there a way to import only what I need or not importing anything from the AWS-SDK at all?有没有办法只导入我需要的内容或根本不从AWS-SDK导入任何内容?

Here is my code:这是我的代码:

import AWS from 'aws-sdk/global'


AWS.config.region = region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: IdentityPoolId
})

From the Cognito SDK docs :来自Cognito SDK 文档

The Amazon Cognito Identity SDK for JavaScript depends on:适用于 JavaScript 的 Amazon Cognito 身份开发工具包取决于:

The CognitoIdentityServiceProvider service from the AWS SDK for JavaScript来自适用于 JavaScript 的 AWS 开发工具包的CognitoIdentityServiceProvider服务

So you can't use it without the regular AWS SDK for JavaScript.因此,如果没有适用于 JavaScript 的常规 AWS 开发工具包,您将无法使用它。 However on that same page it tells you how to create a slimmed down version of the AWS SDK that only includes the needed Cognito dependencies.但是,在同一页面上,它会告诉您如何创建仅包含所需 Cognito 依赖项的精简版 AWS 开发工具包。 It also provides a direct link to a slimmed down version ready to use (but with a different namespace).它还提供了一个指向可供使用的精简版本的直接链接(但具有不同的命名空间)。 I would recommend going here to download a custom version of the SDK that only includes the pieces you need.我建议去这里下载只包含您需要的部分的 SDK 的自定义版本。

There are specialized versions of the AWS SDK just for Cognito and you can build the AWS SDK just for the services that you require.有专门用于 Cognito 的 AWS 开发工具包版本,您可以仅为您需要的服务构建 AWS 开发工具包。

Here is an example just for Cognito:这是一个仅适用于 Cognito 的示例:

Cognito Identity SDK认知身份 SDK

Here is the link to build your own custom AWS SDK:这是构建您自己的自定义 AWS 开发工具包的链接:

AWS SDK for JavaScript in the Browser浏览器中适用于 JavaScript 的 AWS 开发工具包

I recommend customizing the official JavaScript SDK and not using specialized versions as the APIs and use cases can be different or limited in functionality.我建议自定义官方 JavaScript SDK,而不是使用专门的版本,因为 API 和用例在功能上可能不同或有限。

There is a third option which is to not use the AWS SDKs at all and code everything by hand.还有第三种选择,即根本不使用 AWS 开发工具包并手工编写所有内容。 This is definitely for experts as you have to deal directly with the REST API, creating signatures, etc.这绝对适合专家,因为您必须直接处理 REST API、创建签名等。

A Google search will turn up lots of variants of the Cognito SDK.谷歌搜索会发现 Cognito SDK 的许多变体。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM