npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ciam-node-sdk

v1.1.2

Published

[产品快速入口](https://console.cloud.tencent.com/ciam)

Downloads

9

Readme

一、CIAM控制台链接

产品快速入口

二、SDK概览

ciam-node-sdk 提供以下登录鉴权方法:

|方法名称 |描述 |备注 | |:----|:----|:----| |generateLoginUrl |生成认证登录URL |- | |fetchToken |通过code获取token |- | |getUser| 获取用户信息 | - | |logout |退出登录 |- |

三、SDK接口说明

1. 初始化

  • 代码示例
const { NodeClient } = require('ciam-node-sdk'); // node-sdk
const ciam = new NodeClient({
  clientId: ‘your-clientid', // 此处为CIAM的应用ID,CIAM应用中获取
  userDomain: 'your-userDomain', // 此处为租户域名,CIAM域名管理中获取
  redirectUri:'your-redirectUri', // 此处为回调地址,CIAM应用管理中获取
  logoutRedirectUrl: 'your-logoutRedirectUrl', // 此处为退出回调地址,CIAM应用管理中获取
  scopes: ['openid'],
  protocol: 'OIDC_PKCE',
});
  • 参数说明

|参数名 |类型 |是否必填 |长度限制 |描述 | |:----|:----|:----|:----|:---- | |clientId |string |是 |- |管理端添加的小程序应用ID | |userDomain |string |是 |- |租户域名(自定义域名获取) | |redirectUri |string |是 |- |登录成功后跳转的URL | |logoutRedirectUrl |string | 是 |- |登录退出后跳转的URL | |scopes |array[Agreement] |是 |- | 遵循oauth2.0规范,默认为openid | |protocol |string |否 |- |OIDC_PKCE(默认)、OIDC_DEFAULT |

2. 生成认证登录URL

用于生成登录URL,实现快速跳转到CIAM登录页面。

  • 代码示例
// 登录CIAM
app.get('/login', async (req, res) => {
  const url = await ciam.generateAuthUrl();
  res.redirect(url);
})

3. 获取token和用户信息

该方法用于当CIAM登录成功时,根据页面返回的code调用fetchToken,获取到的token用于获取用户信息。

  • 代码示例
// 处理redirect回调
app.get('/callback', async (req, res) => {
  const { code } = req.query;
  const result = await ciam.fetchToken(code);
  const { access_token, id_token } = result;
  const userInfo = await ciam.getUser();
  req.session.user = { ...userInfo };
  res.redirect('/');
})
  • fetchToken参数说明

|参数名 |类型 |是否必填 |长度限制 |描述 | |:----|:----|:----|:----|:---- | | code |string | 是 | 与CIAM认证返回的code相同 | 该参数由CIAM托管并返回 |

4. 退出登录

该方法用于退出CIAM登录。

  • 代码示例
// 退出CIAM登录
app.get('/logout', async (req, res) => {
  if (!req.session.user) {
    res.redirect('/');
  }
  const url = await ciam.logout();
  req.session.destroy();
  res.redirect(url);
})

sample下载

TODO

更新日志

1.1.0 breakchange 去掉pkce模式

1.0.0 feat 支持pkce、授权码模式