@adobe/jwt-auth

中文文档
2.0.0发布于 2023/03/14Apache-2.0TypeScriptCommonJS近 30 天下载 2.8万

Retrieve an authorization token from Adobe via JSON Web Token

原始使用文档
文档目录5 节
  1. Goals
  2. Installation
  3. Common Usage
  4. Contributing
  5. Licensing

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.

parameterintegration namerequiredtypedefault
clientIdAPI Key (Client ID)trueString
technicalAccountIdTechnical account IDtrueString
orgIdOrganization IDtrueString
clientSecretClient secrettrueString
privateKeytrueString
passphrasefalseString
metaScopestrueComma separated Sting or an Array
imsfalseStringhttps://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:

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: "[email protected]",
  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: "[email protected]",
  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: "[email protected]",
  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.

版本与发布记录

@adobe/jwt-auth 共发布 13 个版本,首次发布于 2019/02/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2023/03/143 年前
1.0.12021/04/245 年前
1.0.02021/04/235 年前
0.3.32021/01/265 年前
0.3.12020/01/026 年前
0.3.02019/10/027 年前

关于 @adobe/jwt-auth 的常见问题

@adobe/jwt-auth 是什么?

Retrieve an authorization token from Adobe via JSON Web Token

如何安装 @adobe/jwt-auth?

在项目目录运行 npm install @adobe/jwt-auth,或使用 pnpm add / yarn add / bun add。

@adobe/jwt-auth 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adobe/jwt-auth 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/jwt-auth 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^14.18 || ^16.13 || >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adobe/jwt-auth 可以商用吗?

@adobe/jwt-auth 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/jwt-auth 的下载量有多少?

根据 npm 官方下载统计,@adobe/jwt-auth 在 2026/10/05 – 2026/11/03 这 30 天内被下载 28,377 次,日均约 946 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/jwt-auth 还在维护吗?

最新版本 2.0.0 发布于 2023/03/14(3 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/02/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。