{"id":25046113,"url":"https://github.com/digi1874/sso-api","last_synced_at":"2025-06-28T11:35:18.436Z","repository":{"id":97327140,"uuid":"267332972","full_name":"digi1874/sso-api","owner":"digi1874","description":"Simple Single Sign-On for GO","archived":false,"fork":false,"pushed_at":"2020-05-27T14:04:29.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-31T01:24:48.195Z","etag":null,"topics":["auth","jwt","rsa","sso"],"latest_commit_sha":null,"homepage":"https://login.ys1994.nl/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digi1874.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-27T13:54:32.000Z","updated_at":"2020-06-03T15:05:01.000Z","dependencies_parsed_at":"2023-03-11T01:45:43.144Z","dependency_job_id":null,"html_url":"https://github.com/digi1874/sso-api","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/digi1874/sso-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digi1874%2Fsso-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digi1874%2Fsso-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digi1874%2Fsso-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digi1874%2Fsso-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digi1874","download_url":"https://codeload.github.com/digi1874/sso-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digi1874%2Fsso-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262423177,"owners_count":23308867,"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":["auth","jwt","rsa","sso"],"created_at":"2025-02-06T06:35:15.402Z","updated_at":"2025-06-28T11:35:18.417Z","avatar_url":"https://github.com/digi1874.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Single Sign-On for GO\n\u003e 开放登录系统后端\n\u003e\n\u003e 这是一个开放式登录系统，可供给任何网站做登录用。\n\u003e\n\u003e 系统安全可靠，数据传输安全可靠，JWT验证安全可靠。使用非对称加密后发给数据，不怕传输数据被拦截，服务器临时生成密钥，任何人都没法查看密钥。JWT的密钥也是服务器运行时随机生成。\n\u003e\n\u003e * [前端项目](https://github.com/digi1874/sso-web)\n\u003e #\n\n## 构建\n\u003e 依赖\n\u003e 1. go 1.13+\n\u003e 2. mysql (4.1+，本项目开发时使用5.7；库需要设置为utf8mb4)\n\u003e 3. 项目根目录下创建文件db.json连接mysql数据库\n\u003e\u003e ./db.json\n\u003e\u003e ```\n\u003e\u003e {\n\u003e\u003e   \"user\": \"用户名\",\n\u003e\u003e   \"password\": \"密码\",\n\u003e\u003e   \"localhost\": \"地址\",\n\u003e\u003e   \"databaseName\": \"库名\"\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\u003e 4. 添加纯真ip信息库qqwry.dat文件，来源[纯真](https://github.com/freshcn/qqwry)\n\u003e ```\n\u003e # 开发，开启http://localhost:8021/\n\u003e $ go run main.go -env=dev\n\u003e\n\u003e # 生产程序\n\u003e $ go build\n\u003e ```\n\u003e #\n\n## 接口说明\n\u003e * response status code:\n\u003e\u003e 1. 200: 确定\n\u003e\u003e 2. 400: 错误\n\u003e\u003e 3. 401: 无权限，token无效\n\u003e * response data msg: 回应说明\n\u003e #\n\u003e 1. 获取公钥\n\u003e\u003e * url：/login/rsa\n\u003e\u003e * method: GET\n\u003e\u003e * response data: {\"data\": \"jwtPayload.jwtSignature\"}\n\u003e\u003e 1. jwt secret: Response Headers Date 的 Unix 值 （js: new Date( Wed, 27 May 2020 11:22:10 GMT) / 1000）\n\u003e\u003e 2. 公钥存放在 jwtPayload pub；[例子](https://github.com/digi1874/sso-web/blob/master/src/api/rsa.js)\n\u003e\u003e ```\n\u003e\u003e // get: http://localhost:8021/login/rsa\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e \"data\":\"eyJwdWIiOiJMUzB0TFMxQ1JVZEpUaUJRVlVKTVNVTWdTMFZaTFMwdExTMEtUVWxIWmsxQk1FZERVM0ZIVTBsaU0wUlJSVUpCVVZWQlFUUkhUa0ZFUTBKcFVVdENaMUZFTTFGck9IbDNVR1ZOTDFsbVdHdElMMWx0YWxseVNtRTRSZ3BNTWtjNWVUUmhlVE4yTW1GU1VIRlJlVUZhWjBzM1IyWjBTMU5pT0hwMFdsQkhUbFJvUTFOSVduTmxZbk51U1RkcE0yTk1RV1o0UmxONkswTjNOWFJtQ201MVowTlRXbVJRVG1aNVZIQlllVU4yTUhaT1RVOUNkamRJZFVWcFIyMXFSRmhYY1dsUlIzTkxaVGh3TVdOdFpVMXZZa2RwVFdaTVRGTnpVRU5LTTFjS2RFcDZUamxLVm5CbFMyWmtSbTk0VFRKUlNVUkJVVUZDQ2kwdExTMHRSVTVFSUZCVlFreEpReUJMUlZrdExTMHRMUW89In0.duHJ2lDNFj15k-Ydq1HvMQMNcmiI7GnR2h8A_3Ez3VY\"\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\n\u003e 2. 检查账号是否已存在\n\u003e\u003e * url： /login/number/:number/exist\n\u003e\u003e * method: GET\n\u003e\u003e * response data: {\"data\":Boolean(true:存在；false:不存在)}\n\u003e\u003e ```\n\u003e\u003e // get: http://localhost:8021/login/number/123123/exist\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e   \"data\":true\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\n\u003e 3. 注册账号\n\u003e\u003e * url：/login/register\n\u003e\u003e * method: POST\n\u003e\u003e * Request Content-Type: application/json;charset=UTF-8\n\u003e\u003e * Request Payload: { data: \"账号密码加密串\", host: \"登录网站\" }\n\u003e\u003e 1. rsa加密[例子](https://github.com/digi1874/sso-web/blob/master/src/utils/crypto.js)\n\u003e\u003e 2. rsaEncrypt({ number: 账号, password: 密码 }, 公钥)\n\u003e\u003e * response data: {\"data\":\"jwtPayload.jwtSignature\"}\n\u003e\u003e 1. jwtPayload 使用base64解码后得到 { id: 用户, ip: 用户ip地址, exp: 有效时间unix值 }\n\u003e\u003e ```\n\u003e\u003e // post: http://localhost:8021/login/register\n\u003e\u003e\n\u003e\u003e //Request data:\n\u003e\u003e {\n\u003e\u003e   data: \"p4WV+1flEf+r2ko+8g7rNdGctkxgV90yUw9sVCCLQFR7wsWUdOM4oOhdt08lCdajYvPOjS1/sSBa9gp7RSynIjsc8l2zYWhL75WCVvA0A49GRI8nyr9y3944H7yN3wSA6AODHR/sE7Bdis0cMC7FFh/1DmRwmUEO9alrWAPtDY0=\"\n\u003e\u003e   host: \"www.ys1994.nl\"\n\u003e\u003e }\n\u003e\u003e\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e   \"data\":\"eyJleHAiOjE1ODQ3ODcyNTUsImlkIjoxNCwiaXAiOiIxMjcuMC4wLjEifQ.SbBU8drwIeNuyViPaqnDqGXwipGSkaQq63LOwoQLVOw\"\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\n\u003e 3. 登录\n\u003e\u003e * url：/login/\n\u003e\u003e 1. 注意别少了最后的\"/\"\n\u003e\u003e * method: POST\n\u003e\u003e * Request Content-Type: application/json;charset=UTF-8\n\u003e\u003e * Request Payload: { data: \"账号密码加密串\", host: \"登录网站\" }\n\u003e\u003e 1. rsa加密[例子](https://github.com/digi1874/sso-web/blob/master/src/utils/crypto.js)\n\u003e\u003e 2. rsaEncrypt({ number: 账号, password: 密码 }, 公钥)\n\u003e\u003e * response data: {\"data\":\"jwtPayload.jwtSignature\"}\n\u003e\u003e ```\n\u003e\u003e // post: http://localhost:8021/login/\n\u003e\u003e\n\u003e\u003e //Request data:\n\u003e\u003e {\n\u003e\u003e   data: \"p4WV+1flEf+r2ko+8g7rNdGctkxgV90yUw9sVCCLQFR7wsWUdOM4oOhdt08lCdajYvPOjS1/sSBa9gp7RSynIjsc8l2zYWhL75WCVvA0A49GRI8nyr9y3944H7yN3wSA6AODHR/sE7Bdis0cMC7FFh/1DmRwmUEO9alrWAPtDY0=\"\n\u003e\u003e   host: \"www.ys1994.nl\"\n\u003e\u003e }\n\u003e\u003e\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e   \"data\":\"eyJleHAiOjE1ODQ3ODcyNTUsImlkIjoxNCwiaXAiOiIxMjcuMC4wLjEifQ.SbBU8drwIeNuyViPaqnDqGXwipGSkaQq63LOwoQLVOw\"\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\n\u003e 4. 修改密码\n\u003e\u003e * url：/login/password\n\u003e\u003e * method: POST\n\u003e\u003e * Request Content-Type: application/json;charset=UTF-8\n\u003e\u003e * Request Payload: { data: \"账号密码加密串\" }\n\u003e\u003e 1. rsa加密[例子](https://github.com/digi1874/sso-web/blob/master/src/utils/crypto.js)\n\u003e\u003e 2. rsaEncrypt({ signature: jwtSignature, password: 当前密码, newPassword: 新密码 }, 公钥)\n\u003e\u003e * response data: {\"data\":\"密码修改成功\"}\n\u003e\u003e ```\n\u003e\u003e // post: http://localhost:8021/password\n\u003e\u003e\n\u003e\u003e //Request data:\n\u003e\u003e {\n\u003e\u003e   data: \"Z37MlUjJAOtL1EdtvWXHjfx69/3g79dAxXgxUnymw5xiDluJ0FHOiGCucWFDg+MTZEHTPdJudzfKvl6liNGqJxar4f0k+Er49Az0yrKDZxmcXGeC8bF+W88F+N0yKSSKfh50QYQTM0D30OA2ZqLQEVEBjKDoBEtL/WU7lt8N2t8=\"\n\u003e\u003e }\n\u003e\u003e\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e   \"data\":\"密码修改成功\"\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\n\u003e 5. 检查token(jwtPayload.jwtSignature)是否有效\n\u003e\u003e * url：/login/verify/:token\n\u003e\u003e * method: GET\n\u003e\u003e * response data: {\"data\":Boolean(true:有效；false:无效)}\n\u003e\u003e ```\n\u003e\u003e // get: http://localhost:8021/login/verify/eyJleHAiOjE1ODQ3NzQyNDMsImlkIjo1LCJpcCI6IjEyNy4wLjAuMSJ9.yaedlsXNNLFxYGknWAPU-ncpUS936V5AigJPWfS3ZxY\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e   \"data\":true\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n\n\u003e 6. 获取登录列表\n\u003e\u003e * url：/login/list/:token(jwtPayload.jwtSignature)\n\u003e\u003e * method: GET\n\u003e\u003e * query:\n\u003e\u003e 1. page: 页数\n\u003e\u003e 1. size: 每页数量\n\u003e\u003e * response data: {\"data\":Boolean(true:有效；false:无效)}\n\u003e\u003e ```\n\u003e\u003e // get: http://localhost:8021/login/verify/eyJleHAiOjE1ODQ3NzQyNDMsImlkIjo1LCJpcCI6IjEyNy4wLjAuMSJ9.yaedlsXNNLFxYGknWAPU-ncpUS936V5AigJPWfS3ZxY\n\u003e\u003e // response data:\n\u003e\u003e {\n\u003e\u003e   \"data\":{\n\u003e\u003e     \"count\": 2,        // 总数\n\u003e\u003e     \"page\": 1,         // 当前页数\n\u003e\u003e     \"size\": 20,        // 每页数量\n\u003e\u003e     \"data\": [          // 列表\n\u003e\u003e       {\n\u003e\u003e         \"ip\": \"119.129.224.186\",       // 用户ip\n\u003e\u003e         \"country\": \"广东省广州市\",      // 用户地区\n\u003e\u003e         \"exp\": 1584690154,             // 登录过期时间\n\u003e\u003e         \"message\": \"\",                 // 一些信息\n\u003e\u003e         \"state\": 1,                    // 1: 正常；2: 退出\n\u003e\u003e         \"createdTime\": 1584085354    // 登录时间\n\u003e\u003e       },\n\u003e\u003e       {\n\u003e\u003e         \"ip\": \"119.129.224.186\",\n\u003e\u003e         \"country\": \"广东省广州市\",\n\u003e\u003e         \"exp\": 0,\n\u003e\u003e         \"message\": \"登录密码错误\",\n\u003e\u003e         \"state\": 2,\n\u003e\u003e         \"createdTime\": 1584085354    // 登录时间\n\u003e\u003e       }\n\u003e\u003e     ]\n\u003e\u003e   }\n\u003e\u003e }\n\u003e\u003e ```\n\u003e\u003e #\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigi1874%2Fsso-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigi1874%2Fsso-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigi1874%2Fsso-api/lists"}