# yapi-plugin-kc-oidc **Repository Path**: smalleyes/yapi-plugin-kc-oidc ## Basic Information - **Project Name**: yapi-plugin-kc-oidc - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-12-14 - **Last Updated**: 2024-12-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # yapi-plugin-kc-oidc fork from [yapi-plugin-oidc](https://gitee.com/joshu/yapi-plugin-oidc.git) 第三方插件,OIDC登录,在生成的配置文件中,添加如下配置即可: ```json "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` 授权URL - `tokenUrl` 获取access_token URL - `userUrl` 获取用户信息URL - `callbackUrl` 重定向回调URL - `clientId` clientId或者appId - `clientSecret` clientSecret或者appSecret - `scope` 授权范围 - `emailKey` 用户信息电子邮件字段key - `userKey` 用户信息用户名字段key - `emailPostfix` 邮箱后缀 ## 使用方法如下: 1. 将插件配置加入到config.json文件中,**注意:因为后边步骤编译时会将部分配置项写入到前端静态代码,所以需要先将配置项设置为真实值**。 > 需设置为真实值的配置项为:`authUrl`, `callbackUrl`, `clientId`, `scope` ```json { "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" # 可选 } } ] } ``` 2. 在config.json 这层目录下运行 `yapi plugin --name yapi-plugin-kc-oidc` 命令,进行安装编译 > 本步骤做了以下事情,如果你自己做docker镜像,可以手动完成 > > 2.0 进入工作目录 > > ```bash > cd yapi/vendors > ``` > > 2.1 安装所有依赖包 > > > 安装过程中可能出现**node-sass**报错,替换到新的版本就可解决,比如我将`"node-sass": "^4.9.0"` 替换成了 `"node-sass": "^4.14.0"` > > > > ```bash > > sed -i s/'"node-sass": "^4.9.0"'/'"node-sass": "^4.14.0"'/ package.json > > ``` > > > > > > ```bash > npm install --registry https://registry.npm.taobao.org > ``` > > 2.2 安装`ykit`工具 > > ```bash > npm install -g ykit --registry https://registry.npm.taobao.org > ``` > > 2.3 安装`yapi-plugin-kc-oidc` > > ```bash > npm install yapi-plugin-kc-oidc --registry https://registry.npm.taobao.org > ``` > > 或者不用npm安装,自己去git clone代码 > > ```bash > cd node_modules && git clone --depth 1 https://gitee.com/joshu/yapi-plugin-kc-oidc.git > ``` > > 2.4 开始编译 > > ```bash > cd yapi/vendors > npm run build-client # 或执行 NODE_ENV=production ykit pack -m > ``` > > 3. 重启服务