yapi-plugin-hoauth2

1.0.1 • Public • Published

yapi-plugin-hoauth2

License Node Version NPM Version Downloads

第三方插件,基于Oauth2协议登录,在生成的配置文件中,添加如下配置即可:

  "plugins": [
    {
      "name": "auth2",
      "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

Readme

Keywords

none

Package Sidebar

Install

npm i yapi-plugin-hoauth2

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

8.55 kB

Total Files

8

Last publish

Collaborators

  • lester0301