SDK for 单点登录
Authing SSO SDK 用于发起 SSO 登录、查询 SSO 登录状态、单点登出。
安装
通过 NPM 安装
$ npm install @authing/sso --save接着可以通过以下方式使用
import AuthingSSO from "@authing/sso";通过 CDN 安装
<script src="https://cdn.jsdelivr.net/npm/@authing/sso/dist/AuthingSSO.umd.min.js"></script>
<script>
console.log(AuthingSSO);
</script>开始使用
需要先注册一个 Authing 账号,并创建一个 OIDC 应用。
发起登录
跳转登录
窗口登录
业务域名回调地址需要托管一个 html 文件,用于将得到的 code access_token id_token 等参数,通过 postMessage 的方式发送给父窗口,然后将本窗口关闭。
例如,回调地址填写的是 https://example.com/handle.html,这个 html 内部需要编写一段发送 postMessage 的代码,负责从 url 中取出相关参数并传递给父窗口。
Github 参考代码:https://github.com/Authing/oidc-window
查询登录状态
登出
API
AuthingSSO.prototype.constructor
构造函数,接受一个对象作为参数。对象中的参数列表如下:
参数名
是否必填
描述
默认
appId
是
SSO 应用的 ID
-
appDomain
是
SSO 应用域名,例如 app1.authing.cn
-
appType
否
SSO 应用的 类型,可选值为 oidc,oauth,saml
oidc
state
否
自定义字符串,回调地址也会受到此参数,内容相同,可用于传递信息
随机字符串
host
否
一个对象,用于指定 GraphQL 地址
{
oauth: 'https://oauth.authing.cn/graphql' }
host.oauth
否
GraphQL 通信地址
https://oauth.authing.cn/graphql
responseType
否
SSO 应用授权流程,可选值为 code,implicit
code
redirectUrl
否
SSO 应用回调域名
在 Authing 控制台配置的第一个业务域名
nonce
否
随机数
随机数
timestamp
否
时间戳
当前时间戳
示例
AuthingSSO.prototype.login
示例
AuthingSSO.prototype.trackSession
示例
AuthingSSO.prototype.logout
示例
获取帮助
Join us on Gitter: #authing-chat
Last updated
Was this helpful?