{"id":21117162,"url":"https://github.com/hezhii/nodejs-sso-example","last_synced_at":"2025-07-08T20:30:35.593Z","repository":{"id":45776050,"uuid":"102350549","full_name":"hezhii/nodejs-sso-example","owner":"hezhii","description":"🌰 一个基于 Node.js 实现的单点登录实例。","archived":false,"fork":false,"pushed_at":"2017-09-07T11:28:38.000Z","size":13,"stargazers_count":54,"open_issues_count":0,"forks_count":16,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-04T09:36:06.400Z","etag":null,"topics":["nodejs","sso"],"latest_commit_sha":null,"homepage":"","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/hezhii.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":"2017-09-04T10:43:17.000Z","updated_at":"2024-12-07T07:47:28.000Z","dependencies_parsed_at":"2022-08-28T11:51:15.525Z","dependency_job_id":null,"html_url":"https://github.com/hezhii/nodejs-sso-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hezhii/nodejs-sso-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhii%2Fnodejs-sso-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhii%2Fnodejs-sso-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhii%2Fnodejs-sso-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhii%2Fnodejs-sso-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hezhii","download_url":"https://codeload.github.com/hezhii/nodejs-sso-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hezhii%2Fnodejs-sso-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264343447,"owners_count":23593712,"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":["nodejs","sso"],"created_at":"2024-11-20T02:39:39.850Z","updated_at":"2025-07-08T20:30:35.304Z","avatar_url":"https://github.com/hezhii.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js 单点登录实例\n\n一个基于 Express 实现的 Node.js 单点登录实例，核心思路是通过重定向到统一的认证中心进行登录验证。\n\n不过，通过研究淘宝 \u0026 天猫、京东和谷歌的单点登录机制发现，他们都是通过跨域设置 cookie 来实现的，其中淘宝和京东通过 JSONP 设置，谷歌通过重定向方式设置，计划日后通过这样的方式再实现一个例子。\n\n## 如何测试\n\n运行 Demo 需要先安装 Node.js 和 Yarn。\n\n1. **克隆仓库并安装依赖**：\n\n```bash\n$ git clone https://github.com/hezhii/nodejs-sso-example.git\n$ cd nodejs-sso-example\n$ yarn install\n```\n\n2. **启动服务**\n\n启动服务前先修改本地的 hosts 文件，macOS 位于 `/private/etc/hosts`，windows 位于 `C:\\Windows\\System32\\drivers\\etc\\hosts`。\n  \n在文件最后加上一行：`127.0.0.1 www.a.com www.b.com passport.com`\n  \n然后分别启动三个服务：\n  \n```bash\n$ cd passport\n$ node app.js\n$ cd ../system\n$ PORT=8081 SERVER_NAME=a node app.js\n$ PORT=8082 SERVER_NAME=b node app.js\n```\n\n3. **测试**\n\n打开浏览器访问 `www.a.com:8081`，发现会被重定向到 `passport.com`，输入用户名和密码后登录。\n\n接着新开一个窗口访问 `www.b.com:8082`，发现不需要登录直接可以访问。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhezhii%2Fnodejs-sso-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhezhii%2Fnodejs-sso-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhezhii%2Fnodejs-sso-example/lists"}