@bity/oauth2-auth-code-pkce

中文文档
2.13.0发布于 2021/06/10Apache-2.0TypeScriptCommonJS零依赖近 30 天下载 2.3万

An OAuth 2.0 client that ONLY supports Authorization Code flow with PKCE support.

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Exposing other query string parameters on return
  4. Extra parameters which other OAuth servers require
  5. Module systems supported
  6. Development
  7. Publishing to NPM

OAuth2AuthCodePKCE client

A zero dependency OAuth 2.0 client supporting only the authorization code grant (RFC 6749 § 4.1) with PKCE (RFC 7636) for client side protection.

Currently the only Type/JavaScript implementation in public existence.

1 file implementation for easy auditing.

Installation

npm install @bity/oauth2-auth-code-pkce

Usage

See the source code of tests/panel.html. It's commented with helpful information.

Run npm run serve:tests and navigate to http://localhost:8080/tests/panel.html

This page acts as a test panel for various scenarios. Play around! :)

Modify the example to use the correct configuration.

Exposing other query string parameters on return

Some OAuth servers will return additional parameters to the requester. In order to access these they must be explicitly asked for:

config.explicitlyExposedTokens = ['open_id'];

Then this will be available as a property: accessContext.explicitlyExposedTokens.open_id.

Extra parameters which other OAuth servers require

It is probable you will encounter an OAuth server which requires some additional parameters. In order to pass extra parameters, add the following to the configuration:

config.extraAuthorizationParameters = { 'some_query_string_param': 'value', ... };

If you have values which need to be computed at run-time and then passed, you can pass them like so:

oauth2.fetchAuthorizationCode({ 'another_query_string_param': computedValue });

Module systems supported

Module systemFile
Browser (window)index.umd.js
CommonJS (require e.g. nodejs)index.js
TypeScriptindex.ts

Development

Publishing to NPM

Grab the NPM-generated bity-oauth2-auth-code-pkce-*.tgz tarball from CI and then use npm publish $tarball to publish it to NPM.

版本与发布记录

@bity/oauth2-auth-code-pkce 共发布 26 个版本,首次发布于 2019/10/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.13.0latest2021/06/105 年前
2.12.02021/02/125 年前
2.11.02020/10/076 年前
2.10.12020/10/036 年前
2.9.02020/03/256 年前
2.8.32020/03/256 年前

关于 @bity/oauth2-auth-code-pkce 的常见问题

@bity/oauth2-auth-code-pkce 是什么?

An OAuth 2.0 client that ONLY supports Authorization Code flow with PKCE support.

如何安装 @bity/oauth2-auth-code-pkce?

在项目目录运行 npm install @bity/oauth2-auth-code-pkce,或使用 pnpm add / yarn add / bun add。

@bity/oauth2-auth-code-pkce 支持 TypeScript 吗?

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

@bity/oauth2-auth-code-pkce 支持 ESM 还是 CommonJS?

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

@bity/oauth2-auth-code-pkce 可以商用吗?

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

@bity/oauth2-auth-code-pkce 的下载量有多少?

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

@bity/oauth2-auth-code-pkce 还在维护吗?

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