@adobe/jwt-auth 中文文档教程

发布于 3 年前 浏览 8 项目主页 更新于 2 年前

版本 下载/周 codecov 许可”></a> 
  <a href=Language grade: JavaScript

jwt-auth

通过 JWT 路径检索 Adob​​e bearer token

Goals

而不是每个想要使用 JWT Auth 的开发人员从 Adob​​e 检索身份验证令牌的流程必须编写他们自己的此流程的实现此包旨在用一个方法调用替换此需求。

Installation

有关如何将代码下载/安装到您的机器上的说明。

示例:

npm install @adobe/jwt-auth

Common Usage

代码的使用说明。

基于承诺的示例:基于

const auth = require("@adobe/jwt-auth");

auth(config)
  .then((tokenResponse) => console.log(tokenResponse))
  .catch((error) => console.log(error));

异步/等待的示例:

const auth = require("@adobe/jwt-auth");

let tokenResponse = await auth(config);
console.log(tokenResponse);

或者(如果您不关心令牌响应中的其他属性)

const auth = require("@adobe/jwt-auth");

let { access_token } = await auth(config);
console.log(access_token);

Config object

配置对象是您将所有必需和可选参数传递给 auth 打电话。

parameter integration name required type default
clientId API Key (Client ID) true String
technicalAccountId Technical account ID true String
orgId Organization ID true String
clientSecret Client secret true String
privateKey true String
passphrase false String
metaScopes true Comma separated Sting or an Array
ims false String https://ims-na1.adobelogin.com

为了确定您需要注册哪些 metaScopes,您可以在此 方便的表格

例如,如果您需要通过身份验证才能为 GDPR 和用户管理调用 API,您将 查找它们 并发现它们是:

  • GDPR: https://ims-na1.adobelogin.com/s/entgdprsdk
  • User Management: https://ims-na1.adobelogin.com/s/entusersdk

您将创建一个 metaScopes 数组作为配置对象的一部分。 例如:

const config = {
  clientId: "asasdfasf",
  clientSecret: "aslfjasljf-=asdfalasjdf==asdfa",
  technicalAccountId: "asdfasdfas@techacct.adobe.com",
  orgId: "asdfasdfasdf@AdobeOrg",
  metaScopes: [
    "https://ims-na1.adobelogin.com/s/ent_gdpr_sdk",
    "https://ims-na1.adobelogin.com/s/ent_user_sdk",
  ],
};

但是,如果您省略 IMS url,程序包将在调用生成 JWT 时自动为您添加它。 例如:

const config = {
  clientId: "asasdfasf",
  clientSecret: "aslfjasljf-=asdfalasjdf==asdfa",
  technicalAccountId: "asdfasdfas@techacct.adobe.com",
  orgId: "asdfasdfasdf@AdobeOrg",
  metaScopes: ["ent_gdpr_sdk", "ent_user_sdk"],
};

这是推荐的方法。

Response Object

响应对象包含三个键:

  • token_type
  • access_token
  • expires_in

Example

const auth = require("@adobe/jwt-auth");
const fs = require("fs");

const config = {
  clientId: "asasdfasf",
  clientSecret: "aslfjasljf-=asdfalasjdf==asdfa",
  technicalAccountId: "asdfasdfas@techacct.adobe.com",
  orgId: "asdfasdfasdf@AdobeOrg",
  metaScopes: ["ent_dataservices_sdk"],
};
config.privateKey = fs.readFileSync("private.key");

auth(config)
  .then((token) => console.log(token))
  .catch((error) => console.log(error));

Contributing

欢迎贡献! 阅读贡献指南了解更多信息。

Licensing

这个项目是根据 Apache V2 许可证获得许可的。 有关详细信息,请参阅许可证

Version Downloads/week codecov License Language grade: JavaScript

jwt-auth

Retrieve an Adobe bearer token via the JWT path

Goals

Instead of every developer who wants to use the JWT Auth flow to retrieve an auth token from Adobe having to write their own implementation of this flow this package is intended to replace this need with one method call.

Installation

Instructions for how to download/install the code onto your machine.

Example:

npm install @adobe/jwt-auth

Common Usage

Usage instructions for your code.

Promise based example:

const auth = require("@adobe/jwt-auth");

auth(config)
  .then((tokenResponse) => console.log(tokenResponse))
  .catch((error) => console.log(error));

Async/Await based example:

const auth = require("@adobe/jwt-auth");

let tokenResponse = await auth(config);
console.log(tokenResponse);

or (if you don't care about the other properties in the token response)

const auth = require("@adobe/jwt-auth");

let { access_token } = await auth(config);
console.log(access_token);

Config object

The config object is where you pass in all the required and optional parameters to the auth call.

parameter integration name required type default
clientId API Key (Client ID) true String
technicalAccountId Technical account ID true String
orgId Organization ID true String
clientSecret Client secret true String
privateKey true String
passphrase false String
metaScopes true Comma separated Sting or an Array
ims false String https://ims-na1.adobelogin.com

In order to determine which metaScopes you need to register for you can look them up by product in this handy table.

For instance if you need to be authenticated to call API's for both GDPR and User Management you would look them up and find that they are:

  • GDPR: https://ims-na1.adobelogin.com/s/entgdprsdk
  • User Management: https://ims-na1.adobelogin.com/s/entusersdk

They you would create an array of metaScopes as part of the config object. For instance:

const config = {
  clientId: "asasdfasf",
  clientSecret: "aslfjasljf-=asdfalasjdf==asdfa",
  technicalAccountId: "asdfasdfas@techacct.adobe.com",
  orgId: "asdfasdfasdf@AdobeOrg",
  metaScopes: [
    "https://ims-na1.adobelogin.com/s/ent_gdpr_sdk",
    "https://ims-na1.adobelogin.com/s/ent_user_sdk",
  ],
};

However, if you omit the IMS url the package will automatically add it for you when making the call to generate the JWT. For example:

const config = {
  clientId: "asasdfasf",
  clientSecret: "aslfjasljf-=asdfalasjdf==asdfa",
  technicalAccountId: "asdfasdfas@techacct.adobe.com",
  orgId: "asdfasdfasdf@AdobeOrg",
  metaScopes: ["ent_gdpr_sdk", "ent_user_sdk"],
};

This is the recommended approach.

Response Object

The response object contains three keys:

  • token_type
  • access_token
  • expires_in

Example

const auth = require("@adobe/jwt-auth");
const fs = require("fs");

const config = {
  clientId: "asasdfasf",
  clientSecret: "aslfjasljf-=asdfalasjdf==asdfa",
  technicalAccountId: "asdfasdfas@techacct.adobe.com",
  orgId: "asdfasdfasdf@AdobeOrg",
  metaScopes: ["ent_dataservices_sdk"],
};
config.privateKey = fs.readFileSync("private.key");

auth(config)
  .then((token) => console.log(token))
  .catch((error) => console.log(error));

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文