AWSCognito资源服务器标识符和作用域资源服务器的引入。
创始人
2024-09-24 14:32:08
0

在AWS Cognito身份池中,资源服务器是代表API资源的标识符。对于每个资源服务器,您可以定义作用域,并将其分配给客户端。

使用AWS Cognito身份池时,您需要配置资源服务器和对应的作用域。下面是示例代码:

// 配置 AWS Cognito 身份池
const AWS = require('aws-sdk/global');
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');

global.fetch = require('node-fetch');

const authenticationData = {
    Username : 'username',
    Password : 'password',
};

const authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);

const poolData = {
    UserPoolId : 'pool-id',
    ClientId : 'client-id',
};

const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

const userData = {
    Username : 'username',
    Pool : userPool,
};

const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        console.log(' access token + ' + result.getAccessToken().getJwtToken());
        const accessToken = result.getAccessToken().getJwtToken();
        
        // 定义资源服务器
         const resourceServer = {
            userPoolId: 'pool-id',
            identifier: 'resource-server-identifier',
            name: 'resource-server-name',
            scopes: [
                {
                    scopeName: 'scope-1',
                    scopeDescription: 'This is scope 1'
                },
                {
                    scopeName: 'scope-2',
                    scopeDescription: 'This is scope 2'
                }
            ]
        };

        // 创建 AWS Cognito 资源服务器
        const params = {
            AccessToken: accessToken,
            UserPoolId: resourceServer.userPoolId,
            Identifier: resourceServer.identifier,
            Name: resourceServer.name,
            Scopes: resourceServer.scopes
        };
        const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
        cognitoidentityserviceprovider.createResourceServer(params, function(err, data) {

相关内容

热门资讯

关于!微信微乐自建房辅助工具,... 关于!微信微乐自建房辅助工具,微乐家乡麻将自建房辅助app(开挂自建房)方法1)微乐家乡麻将自建房辅...
大家学习交流!微信卡五星辅助器... 大家学习交流!微信卡五星辅助器,微乐小程序免费黑科技(开挂自建房)方法1、很好的工具软件,可以解锁游...
三分钟了解!微乐微信自建房辅助... 三分钟了解!微乐微信自建房辅助工具插件,微乐家乡麻将自建房辅助app(开挂自建房)工具1、三分钟了解...
一分钟教会你!微乐家乡麻将自建... 一分钟教会你!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)方法1、用户打开应用...
分享实测!微信微乐自建房辅助工... 分享实测!微信微乐自建房辅助工具,微乐自建房脚本免费入口(开挂自建房)器1、起透看视 微信微乐自建房...
重大通报!微乐自建房辅助工具脚... 重大通报!微乐自建房辅助工具脚本,微乐小程序免费黑科技(开挂自建房)app微乐自建房辅助工具脚本破解...
如何分辨真伪!微乐微信自建房辅... 如何分辨真伪!微乐微信自建房辅助工具插件,微乐小程序免费黑科技(开挂自建房)技巧1、微乐微信自建房辅...
我来教教你!微乐自建房辅助工具... 我来教教你!微乐自建房辅助工具挂,微乐家乡麻将自建房辅助app(开挂自建房)工具1、玩家可以在微乐家...
重大来袭!微乐自建房辅助工具神... 重大来袭!微乐自建房辅助工具神器,微乐小程序免费黑科技(开挂自建房)器1、游戏颠覆性的策略玩法,独创...
带你了解!微信卡五星辅助器,微... 带你了解!微信卡五星辅助器,微乐自建房脚本免费入口(开挂自建房)方法1、带你了解!微信卡五星辅助器,...