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

@oneauth/sdk-core

v0.0.5

Published

oneauth sdk

Downloads

17

Readme

@oneauth/sdk-core

@oneauth/sdk-core 可单独使用。@oneauth/sdk-core 会提供登录登出和鉴权所需的方法。

也可搭配@oneauth/sdk-react 或者@oneauth/sdk-vue 使用。

@oneauth/sdk-react 和@oneauth/sdk-vue 中会提供对路由的鉴权功能和准备好的登录重定向页面

安装

npm install --save  @oneauth/sdk-core

初始化 sdk

初始化时需要传入 issuerclientIdredirectUriscopes, 这些值可以从 oneauth 控制台得到 初始化 sdk 之后,

参数

  1. issuer:将租户名替换成实际的名字
  2. redirectUri: 指向登录回调页面,登录完成后会将 code 和 state 或错误信息,作为 query 传递到这个 url 上。在@oneauth/vue, @oneauth/vue-next, @oneauth/react 中提供了<login-callback />组件,将该组件挂在到 redirectUri 上,后自动处理返回的信息
  3. clientId: 在 oneauth 控制台的应用详情页面可得到
  4. scopes: 可照如下填写
import OneAuth from '@oneauth/sdk-core';
const oneAuth = new OneAuth({
  issuer: `https://${租户名}.oneauth.cn/oauth/v1`,
  clientId: `2YXXZ78611K0c8906MX6RJ8c0s84VcQB`,
  redirectUri: `http://localhost:3000/callback`,
  scopes: ['openid', 'profile', 'email'],
});

方法

  1. 登录

调用oneauth.login,传入redirectUri参数,则会在登录完成之后跳转回这个网址

oneauth.login({
  redirectUri: 'http://localhost:3000/redirectUri',
});
  1. 登出当前应用。当前应用会被登出,当在 OneAuth 上的登录状态会被保留

调用oneauth.logoutThisApp

oneauth.logoutThisApp();
  1. 登出 OneAuth

调用oneauth.logoutOneAuth, 传入redirectUri参数,将会在登出完成之后跳转到这个网址

oneauth.logoutOneAuth({
  redirectUri: 'http://location:3000/xxx',
});
  1. 获取 accessToken
const accessToken = oneauth.accessToken;
  1. 获取 idToken
const idToken = oneauth.idToken;
  1. 获取用户信息

可传入泛型,以获得类型约束

type User = unknown;
const userInfo = await oneauth.getUserInfo<User>();
  1. 获取当前用户的登录状态
/**
 * 是否登录了
 **/
const isAuthed = await oneauth.isAuthenticated();
  1. 校验从登录重定向页面获取的 code 和 state

登录之后,oneauth 会重定向到实例化时传入的redirectUri对应的页面。

并在 query 中带上参数codestate

将参数传入本方法,返回布尔值,标识 code 是否有效

const isValid = await oneauth.verify(code, state);