@girder/oauth-client

中文文档
0.8.0发布于 2022/02/26Apache-2.0TypeScriptCommonJS近 30 天下载 2749

A TypeScript library for performing OAuth login to a Girder 4 (Django) server.

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录4 节
  1. Description
  2. Usage
  3. Example app
  4. Development

girder-oauth-client

npm (scoped)

A TypeScript library for performing OAuth login to a Girder 4 (Django) server.

Description

This provides support for authenticating with Girder 4 servers, using the OAuth2.0 Authorization Code Grant with PKCE flow.

Usage

  • Install the library:

    yarn add @girder/oauth-client
    

    or if you're using npm:

    npm install @girder/oauth-client
    
  • Instantiate an OauthClient with your application-specific configuration:

    import OauthClient from '@girder/oauth-client';
    
    const oauthClient = new OauthClient(
      new URL(process.env.OAUTH_API_ROOT), // e.g. 'http://localhost:8000/oauth/'
      process.env.OAUTH_CLIENT_ID, // e.g. 'Qir0Aq7AKIsAkMDLQe9MEfORbHEBKsViNhAKJf1A'
    );
    
  • Call redirectToLogin when it's time to start a login flow:

    document.querySelector('#sign-in-link').addEventListener('click', (event) => {
      event.preventDefault();
      oauthClient.redirectToLogin();
      // This will redirect away from the current page
    });
    
  • At the start of every page load, unconditionally call maybeRestoreLogin, to attempt to restore a login state; this will no-op if no login is present. Afterwards, get and store HTTP headers for authentication from authHeaders.

    let authHeaders;
    oauthClient.maybeRestoreLogin()
      .then(() => {
        authHeaders = oauthClient.authHeaders;
      });
    

or, if using ES6 and async/await:

await oauthClient.maybeRestoreLogin();
let { authHeaders } = client;
  • Include these headers with every Ajax API request:

    fetch('http://localhost:8000/api/files', {
      headers: authHeaders,
    });
    
  • The login state will persist across page refreshes. Call logout to clear any active login:

    document.querySelector('#sign-out-link').addEventListener('click', (event) => {
      event.preventDefault();
      oauthClient.logout()
        .then(() => {
          authHeaders = oauthClient.authHeaders;
        });
    });
    

Example app

This repository comes bundled with an example application. Run it with:

git clone https://github.com/girder/girder-oauth-client.git
yarn install
yarn build
cd example
yarn install
yarn serve
# Visit http://localhost:1234/

Development

To develop the library using the example app:

# From the root of the repository
yarn link
yarn install
yarn watch

In another terminal:

# From the root of the repository
cd example
yarn link '@girder/oauth-client'
yarn install
yarn serve

版本与发布记录

@girder/oauth-client 共发布 14 个版本,首次发布于 2020/12/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.8.0latest2022/02/264 年前
0.7.82022/01/294 年前
0.7.72021/03/165 年前
0.7.62021/01/215 年前
0.7.52021/01/215 年前
0.0.02021/01/215 年前

关于 @girder/oauth-client 的常见问题

@girder/oauth-client 是什么?

A TypeScript library for performing OAuth login to a Girder 4 (Django) server.注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @girder/oauth-client?

在项目目录运行 npm install @girder/oauth-client,或使用 pnpm add / yarn add / bun add。

@girder/oauth-client 支持 TypeScript 吗?

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

@girder/oauth-client 支持 ESM 还是 CommonJS?

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

@girder/oauth-client 可以商用吗?

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

@girder/oauth-client 的下载量有多少?

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

@girder/oauth-client 还在维护吗?

最新版本 0.8.0 发布于 2022/02/26(4 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/12/16。作者已将其标记为弃用,新项目建议寻找替代方案。