# oauth-server-example **Repository Path**: justinchou/oauth-server-example ## Basic Information - **Project Name**: oauth-server-example - **Description**: nodejs oauth-server example - **Primary Language**: NodeJS - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2017-01-06 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README OAuth2 Server === # 简介 本工程是使用oauth-server模块的示例, 由于官方没有给出对应的Html文件, 造成开始时测试出现各种问题. 暂时支持 password, refresh_token, authorization_code(推荐) 三种方式, 一般微信等均使用的是authorization_code方式. # 使用 ## 运行 下载代码, 运行 node demo.js 即可 ## 接入文档 1. 准备: 首先, 登陆后台, 注册App账号, 生成Secret密码, 设置回调地址(服务入口). -- 暂时没有后台, 更改model中的文件或数据库表oauthClients进行添加. 例如: model/oauth2/memory/model.js 中增加: oauthClients = [{ clientId: "plane", clientSecret: "THISisAUTO-generatedSECRET", redirectUri: "http://localhost:3001/service" }] 然后设置允许的授权方式. -- 暂时没有后台, 更改model中的文件或数据库表authorizedClientIds进行添加 例如: model/oauth2/memory/model.js 中增加: authorizedClientIds = { "authorization_code": ["plane"] } 最后, 假设用户已经通过网站注册了账号密码 -- 暂时没有注册页面, 更改model中的文件或者数据库表users进行添加 例如: model/oauth2/memory/model.js 中增加: users = [{ id: "4a5604f624c13712ddf51407b384035458634795", username: "justin", password: "123456" }] 2. 服务器接入: 开发服务 index.js 访问其中 /service 接口内需要获取用户信息 参考流程图: AuthFlow.jpg