如何在不使用 Amplify 的情况下使用 Amazon Cognito [英] How to use Amazon Cognito without Amplify

查看:34
本文介绍了如何在不使用 Amplify 的情况下使用 Amazon Cognito的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚进入 Cognito.AWS 设置相当简单直接.

我们有各种应用、网络应用和服务,我们希望它们能够使用 Cognito 服务.我有使用 Auth0 进行类似设置的经验,但由于我们一直在利用许多 Amazon Web Services,因此使用 Cognito 也确实很有意义.

我所到之处,每个指南最终都引用了 Amplify 客户端库和 cli.我们有现有的应用程序和服务,真的不想改变工具或导入任何不必要的东西来增加膨胀和复杂性.有没有办法在没有 Amplify 库的情况下使用 Cognito 服务?是否有用于与 Cognito 服务、身份验证和授权流程交互的轻量级仅 Cognito 客户端库?

解决方案

首先,我想澄清一下放大"是多个事物的总称.我们有:

  1. 放大库 (UI/JS)
  2. 放大 CLI(以创建云原生应用)
  3. Amplify Console(ci/cd 和全栈网络应用托管)
  4. 放大管理用户界面(用于创建和配置全栈网络应用的用户界面)

您可以查看主页以获取更多说明 - https://docs.amplify.aws/<块引用>

是否有用于与 Cognito 服务、身份验证和授权流程交互的轻量级仅 Cognito 客户端库?

在幕后,Amplify 使用 amazon-cognito-identity-js 与 Amazon Cognito 交互的库.您可以通过 npm install amazon-cognito-identity-js 直接安装.

源代码已移至放大库(例如 amplify-js) 存储库.再一次,是放大"的一部分.第一类放大库"下的保护伞.

<块引用>

有没有办法在没有 Amplify 库的情况下使用 Cognito 服务?

您可以采用的另一种方法是使用 Amazon Cognito 作为 OAuth 服务器.当您创建 Amazon Cognito 托管 UI 域时,它为您提供符合 OAuth 2.0 的授权服务器.

您可以为注册/登录端点创建自己的 API/后端,并与 Amazon Cognito OAuth 服务器交换令牌/凭证,而无需使用 aws-sdk 或任何第三方依赖库.

我写了一个演练示例,如何配置你的用户池,你需要使用 Node.js 与之交谈的端点,你可以在这里找到它:https://github.com/oieduardorabelo/node-amazon-cognito-oauth

对于任何其他语言,您都可以遵循相同的想法.

I'm just now diving into Cognito. The AWS setup has been fairly straight-forward, easy.

We have a variety of apps, webapps, and services and we'd like those to make use of the Cognito service. I've experience setting up similar with Auth0, but because we've been leveraging a number of Amazon Web Services, it really makes sense to use Cognito as well.

Everywhere I look, every guide eventually references Amplify client-side library and cli. We have existing apps and services, and really don't want to change tooling or import anything unnecessary to add bloat and complexity. Is there a way to use Cognito service without Amplify libraries? Is there a lightweight Cognito-only client library for interfacing with the Cognito service, authentication-and-authorization flow?

解决方案

To start, I want to clarify that "Amplify" is an umbrella term for multiple things. We have:

  1. Amplify Libraries (UI/JS)
  2. Amplify CLI (to create cloud-native applications)
  3. Amplify Console (ci/cd and hosting for full-stack web apps)
  4. Amplify Admin UI (UI to create and configure full-stack web apps)

You can check the homepage for more clarification - https://docs.amplify.aws/

Is there a lightweight Cognito-only client library for interfacing with the Cognito service, authentication-and-authorization flow?

Behind the scenes, Amplify uses amazon-cognito-identity-js library to interface with Amazon Cognito. You can install that directly via npm install amazon-cognito-identity-js.

The source code has been moved to the Amplify Libraries (e.g. amplify-js) repository. Once again, is part of the "Amplify" umbrella under the first category "Amplify Libraries".

Is there a way to use Cognito service without Amplify libraries?

Another approach that you can do, is to use Amazon Cognito as an OAuth server. When you create an Amazon Cognito Hosted UI Domain, it provides you an OAuth 2.0 compliant authorization server.

You can create your own API/Backend for Signup/Login endpoints and exchange tokens/credentials with the Amazon Cognito OAuth server without using aws-sdk or any 3rd party dependency library.

I wrote a walkthrough example, how to configure your User Pool, endpoints that you need to talk to using Node.js, you can find it here: https://github.com/oieduardorabelo/node-amazon-cognito-oauth

You can follow the same idea for any other language.

这篇关于如何在不使用 Amplify 的情况下使用 Amazon Cognito的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆