{"id":15324385,"url":"https://github.com/amazing-gao/yapi-plugin-auth2","last_synced_at":"2025-04-15T02:50:33.696Z","repository":{"id":43872114,"uuid":"183386317","full_name":"amazing-gao/yapi-plugin-auth2","owner":"amazing-gao","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-09T17:34:42.000Z","size":17,"stargazers_count":5,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T14:39:09.470Z","etag":null,"topics":["yapi","yapi-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amazing-gao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-25T08:02:54.000Z","updated_at":"2024-11-22T09:49:37.000Z","dependencies_parsed_at":"2022-08-12T10:51:20.337Z","dependency_job_id":null,"html_url":"https://github.com/amazing-gao/yapi-plugin-auth2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazing-gao%2Fyapi-plugin-auth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazing-gao%2Fyapi-plugin-auth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazing-gao%2Fyapi-plugin-auth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amazing-gao%2Fyapi-plugin-auth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amazing-gao","download_url":"https://codeload.github.com/amazing-gao/yapi-plugin-auth2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997087,"owners_count":21195797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["yapi","yapi-plugin"],"created_at":"2024-10-01T09:26:28.333Z","updated_at":"2025-04-15T02:50:33.680Z","avatar_url":"https://github.com/amazing-gao.png","language":"JavaScript","readme":"# yapi-plugin-auth2\n\n[license-img]: http://img.shields.io/badge/license-MIT-green.svg\n[license-url]: http://opensource.org/licenses/MIT\n[node-image]: https://img.shields.io/badge/node.js-v6.0.0-blue.svg\n[node-url]: http://nodejs.org/download/\n[npm-img]: https://img.shields.io/npm/v/yapi-plugin-auth2.svg\n[npm-url]: https://npmjs.org/package/yapi-plugin-auth2\n[downloads-image]: https://img.shields.io/npm/dm/yapi-plugin-auth2.svg\n[downloads-url]: https://npmjs.org/package/yapi-plugin-auth2\n\n\n[![License][license-img]][license-url]\n[![Node Version][node-image]][node-url]\n[![NPM Version][npm-img]][npm-url]\n[![Downloads][downloads-image]][downloads-url]\n\n\n第三方插件，基于Oauth2协议登录，在生成的配置文件中，添加如下配置即可：\n\n```\n  \"plugins\": [\n    {\n      \"name\": \"auth2\",\n      \"options\": {\n        \"type\": \"oauth2\",\n        \"clientId\": \"your client id\",\n        \"clientSecret\": \"your client secret\",\n        \"authMethod\": \"GET\",\n        \"authServer\": \"http://your.yapiserver\",\n        \"authPath\": \"登录页面地址\",\n        \"tokenPath\": \"code换取token接口地址\",\n        \"infoPath\": \"用户信息接口地址\",\n        \"redirectUri\": \"http://your.yapiserver/api/plugin/oauth2/callback\",\n        \"userKey\": \"usernamekey\",\n        \"emailKey\": \"emailkey\",\n        \"buttonName\": \"统一登录\",\n        \"authArgs\": {\n          \"login_type\": \"oa\"\n        }\n      }\n    }\n  ]\n```\n使用注意:\n\n- Oauth2服务器用户信息需要提供: `email`和`username`两个字段，如果字段名不一致，可以通过`emailKey`和`userKey`设置。\n\n这里面的配置项含义如下：\n\n- `clientId` 客户端id\n- `clientSecret` 客户端秘钥\n- `authMethod` 调用oauth2服务器地址时的方法，默认**GET**\n- `authServer` oauth2服务器地址\n- `authPath` 授权登录页面地址\n- `tokenPath` 通过code换取token的接口地址\n- `infoPath` 通过token获取用户信息的接口地址\n- `redirectUri` 重定向地址，授权登录页面成功之后携带code跳转的目标地址\n- `state` OAuth state，默认**STATE**\n- `emailKey` 用户信息电子邮件字段key，当值为数组时按优先级尝试获取邮箱\n- `userKey` 用户信息用户名字段key，当值为数组时按优先级尝试获取用户名\n- `buttonName` 登录按钮名称，默认**OAuth2登录**\n- `authArgs` 附加参数，单层json对象，用于格式化到**authPath**, **tokenPath**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazing-gao%2Fyapi-plugin-auth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famazing-gao%2Fyapi-plugin-auth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famazing-gao%2Fyapi-plugin-auth2/lists"}