yapi-plugin-lilithoauth

1.0.21 • Public • Published

yapi-plugin-githuboauth

License Node Version NPM Version Downloads

改了别人的oauth2,试着接入自己的idaas 第三方插件,基于Oauth2协议登录,在生成的配置文件中,添加如下配置即可:

  "plugins": [
    {
      "name": "lilthoauth",
      "options": {
        "type": "oauth2",
        "clientId": "your client id",
        "clientSecret": "your client secret",
        "authMethod": "GET",
        "authServer": "http://your.yapiserver",
        "authPath": "登录页面地址",
        "tokenPath": "code换取token接口地址",
        "infoPath": "用户信息接口地址",
        "redirectUri": "http://your.yapiserver/api/plugin/oauth2/callback",
        "userKey": "usernamekey",
        "emailKey": "emailkey",
        "buttonName": "统一登录",
        "authArgs": {
          "login_type": "oa"
        }
      }
    }
  ]

使用注意:

  • Oauth2服务器用户信息需要提供: emailusername两个字段,如果字段名不一致,可以通过emailKeyuserKey设置。

这里面的配置项含义如下:

  • clientId 客户端id
  • clientSecret 客户端秘钥
  • authMethod 调用oauth2服务器地址时的方法,默认GET
  • authServer oauth2服务器地址
  • authPath 授权登录页面地址
  • tokenPath 通过code换取token的接口地址
  • infoPath 通过token获取用户信息的接口地址
  • redirectUri 重定向地址,授权登录页面成功之后携带code跳转的目标地址
  • state OAuth state,默认STATE
  • emailKey 用户信息电子邮件字段key,当值为数组时按优先级尝试获取邮箱
  • userKey 用户信息用户名字段key,当值为数组时按优先级尝试获取用户名
  • buttonName 登录按钮名称,默认OAuth2登录
  • authArgs 附加参数,单层json对象,用于格式化到authPath, tokenPath

目前我的设置(config.json)

{
"port": "3000",
"adminAccount": "test@test.com",
"db": {
"servername": "mongo",
"DATABASE": "yapi",
"port": "27017"
},
"plugins": [
{
"name": "lilthoauth",
"options": {
"type": "oauth2",
"clientId": "ec64e7930272536c8ce4b179448c7d36zDJz06z7sCL",
"clientSecret": "lgwc23jk8F7yjp0IXCKmi1XjquRusxqIOhuidY5jRO",
"authMethod": "POST",
"authServer": "https://qa-idaas.lilithgames.com",
"authPath": "/oauth/authorize?response_type=code&scope=read&client_id=ec64e7930272536c8ce4b179448c7d36zDJz06z7sCL&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fplugin%2Foauth2%2Fcallback&state=63750159217ad6340c661173d30fcf7ffk01RoHWk33_idp ",
"tokenPath": "/oauth/token",
"infoPath": "/api/bff/v1.2/oauth2/userinfo",
"redirectUri": "http://localhost:3000/api/plugin/oauth2/callback",
"userKey": "username",
"emailKey": "email",
"buttonName": "统一登录",
"authArgs": {
"login_type": "oa"
}
}
},
{
"name": "lilithoauth"
}
]
}

部署:https://github.com/jinfeijie/yapi

  • 装插件步骤(现在卡在验证逻辑问题):
  • 需要把/home/vendors/eslint.js 文件替换为项目里的eslint.js (指定react)
  • 还有/home/vendors/exts/yapi-plugin-import-swagger的都改成false
  • 运行 npm install -g ykit@0.7
  • 运行 yapi plugin --name yapi-plugin-lilithoauth

Dependents (0)

Package Sidebar

Install

npm i yapi-plugin-lilithoauth

Weekly Downloads

1

Version

1.0.21

License

ISC

Unpacked Size

11 kB

Total Files

11

Last publish

Collaborators

  • prosper_liu