1.0.3 • Published 4 years ago
yapi-plugin-kc-oidc v1.0.3
yapi-plugin-kc-oidc
fork from yapi-plugin-oidc
第三方插件,OIDC登录,在生成的配置文件中,添加如下配置即可:
"plugins": [
{
"name": "kc-oidc",
"options": {
"authUrl": "auth url",
"tokenUrl": "token url",
"userUrl": "user urll",
"callbackUrl": "your_yapi_server_host/api/user/login_by_token",
"clientId": "your client id",
"clientSecret": "your client secret",
"scope": "your scope",
"emailKey" : "emailkey", # 可选
"userKey" : "usernamekey", # 可选
"emailPostfix" : "@yapi.com" # 可选
}
}
]
配置项说明:
- Oauth2服务器用户信息需要提供:
email
和username
两个字段,如果字段名不一致,可以通过emailKey
和userKey
设置,如果没有电子邮箱字段,可以使用用户名字段+emailPostfix
属性设置默认电子邮箱地址(电子邮箱是Yapi用户唯一标志)
这里面的配置项含义如下:
authUrl
授权URLtokenUrl
获取access_token URLuserUrl
获取用户信息URLcallbackUrl
重定向回调URLclientId
clientId或者appIdclientSecret
clientSecret或者appSecretscope
授权范围emailKey
用户信息电子邮件字段keyuserKey
用户信息用户名字段keyemailPostfix
邮箱后缀
使用方法如下:
将插件配置加入到config.json文件中,注意:因为后边步骤编译时会将部分配置项写入到前端静态代码,所以需要先将配置项设置为真实值。
需设置为真实值的配置项为:
authUrl
,callbackUrl
,clientId
,scope
{ "port": "3000", "adminAccount": "admin@admin.com", ... "plugins": [ { "name": "oidc", "options": { "authUrl": "auth url", "tokenUrl": "token url", "userUrl": "user urll", "callbackUrl": "your_yapi_server_host/api/user/login_by_token", "clientId": "your client id", "clientSecret": "your client secret", "scope": "your scope", "emailKey" : "emailkey", # 可选 "userKey" : "usernamekey", # 可选 "emailPostfix" : "@yapi.com" # 可选 } } ] }
在config.json 这层目录下运行
yapi plugin --name yapi-plugin-kc-oidc
命令,进行安装编译本步骤做了以下事情,如果你自己做docker镜像,可以手动完成
2.0 进入工作目录
cd yapi/vendors
2.1 安装所有依赖包
安装过程中可能出现node-sass报错,替换到新的版本就可解决,比如我将
"node-sass": "^4.9.0"
替换成了"node-sass": "^4.14.0"
sed -i s/'"node-sass": "^4.9.0"'/'"node-sass": "^4.14.0"'/ package.json
npm install --registry https://registry.npm.taobao.org
2.2 安装
ykit
工具npm install -g ykit --registry https://registry.npm.taobao.org
2.3 安装
yapi-plugin-kc-oidc
npm install yapi-plugin-kc-oidc --registry https://registry.npm.taobao.org
或者不用npm安装,自己去git clone代码
cd node_modules && git clone --depth 1 https://gitee.com/joshu/yapi-plugin-kc-oidc.git
2.4 开始编译
cd yapi/vendors npm run build-client # 或执行 NODE_ENV=production ykit pack -m
重启服务