{"id":16434800,"url":"https://github.com/zce/oauth2-example","last_synced_at":"2025-03-23T08:31:48.191Z","repository":{"id":41884507,"uuid":"187431329","full_name":"zce/oauth2-example","owner":"zce","description":"oauth2 server \u0026 client example","archived":false,"fork":false,"pushed_at":"2023-05-30T23:52:10.000Z","size":202,"stargazers_count":6,"open_issues_count":11,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T18:58:20.339Z","etag":null,"topics":["oauth2","oauth2-client","oauth2-server"],"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/zce.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"zce"}},"created_at":"2019-05-19T03:52:46.000Z","updated_at":"2021-08-05T11:36:23.000Z","dependencies_parsed_at":"2024-10-28T15:53:21.427Z","dependency_job_id":null,"html_url":"https://github.com/zce/oauth2-example","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/zce%2Foauth2-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zce%2Foauth2-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zce%2Foauth2-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zce%2Foauth2-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zce","download_url":"https://codeload.github.com/zce/oauth2-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078067,"owners_count":20557274,"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":["oauth2","oauth2-client","oauth2-server"],"created_at":"2024-10-11T08:50:10.035Z","updated_at":"2025-03-23T08:31:47.749Z","avatar_url":"https://github.com/zce.png","language":"JavaScript","funding_links":["https://github.com/sponsors/zce"],"categories":[],"sub_categories":[],"readme":"# oauth2-example\n\n\u003e oauth2-server example\n\n## Usage\n\n```shell\n# install dependencies\n$ yarn # or npm i\n```\n\n\u003e Client: http://localhost:4000\n\u003e Server: http://localhost:3000\n\nVisit client\n\n## Models\n\n### User\n\n```js\n{\n  id: objectId().str,\n  slug: 'admin',\n  username: 'admin',\n  password: 'wanglei',\n  nickname: 'Administrator',\n  email: 'admin@zce.me',\n  mobile: '13266668888',\n  status: 'activated',\n  scope: ''\n}\n```\n\n### Scope\n\n```js\n{\n  id: objectId().str,\n  scope: 'posts:update',\n  default: false\n}\n```\n\n### Client\n\n```js\n{\n  id: objectId().str,\n  name: 'OAuth2 Client',\n  website_url: 'https://github.com/zce/oauth2-example',\n  privacy_url: 'https://github.com/zce/oauth2-example',\n  key: 'oauth2-client', // client_id\n  secret: 'f657d916-0ad9-4b65-9976-3fe796bbdea0', // client_secret\n  redirects: ['http://localhost:4000/login/callback'], // redirect_uris\n  grants: ['authorization_code', 'password', 'refresh_token', 'client_credentials'],\n  scope: 'all',\n  user_id: 1\n}\n```\n\n### AccessToken\n\n```js\n{\n  id: objectId().str,\n  token: 'faee0258-b0a2-4d38-b12b-e0a9932a6b94', // access_token\n  expires: new Date('2019-05-30 00:00'), // expires_at\n  scope: 'posts:read',\n  user_id: 1,\n  client_id: 1\n}\n```\n\n### RefreshToken\n\n```js\n{\n  id: objectId().str,\n  token: 'cba19635-3bb4-47b1-87f6-8d0ff26b43f2', // refresh_token\n  expires: new Date('2019-05-30 00:00'), // expires_at\n  scope: 'posts:read',\n  user_id: 1,\n  client_id: 1\n}\n```\n\n### AuthorizationCode\n\n```js\n{\n  id: objectId().str,\n  code: '4023348b5bc4', // authorization_code\n  expires: new Date('2019-05-30 00:00'), // expires_at\n  redirect: 'http://localhost:4000/login/callback', // redirect_uri\n  scope: 'posts:read',\n  user_id: 1,\n  client_id: 1\n}\n```\n\n## Grant Types\n\n### Authorization Code\n\n应用站点：FooApp\n授权站点：AuthApp\n\n1. 用户在 FooApp 上点击 AuthApp 授权登录链接，例如：\n   http://localhost:3000/oauth/authorize?client_id=oauth2-example-client\u0026redirect_uri=http://localhost:4000/login/callback\u0026response_type=code\u0026scope=posts:read\n\n2. 用户进入 AuthApp 页面进行授权，如果当前用户还没有在 AuthApp 登录，则需要先跳转到 AuthApp 登录\n   http://localhost:3000/account/login?redirect=%2Foauth%2Fauthorize%3Fclient_id%3Doauth2-example-client%26redirect_uri%3Dhttp%3A%2F%2Flocalhost%3A4000%2Flogin%2Fcallback%26response_type%3Dcode%26scope%3Dposts%3Aread\n\n\u003c!--\n## References\n\n### oauth2orize\n\nhttps://github.com/FrankHassanabad/Oauth2orizeRecipes\nhttps://github.com/primo-malvado/calafrio\nhttps://github.com/at0g/oauth2-demo-server\nhttp://www.passportjs.org\nhttps://blog.csdn.net/shinepan/article/details/78851886\nhttps://github.com/YardStrong/express-oauth-demo\nhttps://www.jianshu.com/p/7febbe553c83\nhttps://github.com/RobottDog/DCOS-Auth\nhttps://github.com/syntithenai/react-express-oauth-login-system\nhttps://github.com/manjeshpv/node-oauth2-server-implementation\nhttps://github.com/oauth-xx/oauth2\nhttps://tools.ietf.org/html/rfc6749\nhttps://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/\nhttps://github.com/greenspanx/node_oauth2_rest_api/blob/master/server.js\nhttps://github.com/zhanghengxin/test-oauth2/blob/master/oauth-model/model.js\nhttps://github.com/slavab89/oauth2-server-example-mongodb\n\n请求授权\n\nGET /authorize\n  client_id: 9c16d1d9d4235bb723c4\n  redirect_uri: https%3A%2F%2Flearn.co%2Fusers%2Fauth%2Fgithub%2Fcallback\n  response_type: code\n  state: 7947e14af4fd2607a8d47072a91fc5ffeea414aad803eb9f\n\n认证服务器如果没有登陆调整到认证服务器的登陆页\n\nGET /login\n  client_id: 9c16d1d9d4235bb723c4\n  return_to: %2Flogin%2Foauth%2Fauthorize%3Fclient_id%3D9c16d1d9d4235bb723c4%26redirect_uri%3Dhttps%253A%252F%252Flearn.co%252Fusers%252Fauth%252Fgithub%252Fcallback%26response_type%3Dcode%26state%3D7947e14af4fd2607a8d47072a91fc5ffeea414aad803eb9f\n\n用户在认证服务器登陆\n\nPOST /session\n  commit: Sign in\n  utf8: ✓\n  authenticity_token: \u003cyour token\u003e\n  login: zce\n  password: \u003cyour password\u003e\n  webauthn-support: supported\n\n跳转到授权页面\n\nGET /authorize\n  client_id: 9c16d1d9d4235bb723c4\n  redirect_uri: https://learn.co/users/auth/github/callback\n  response_type: code\n  state: 7947e14af4fd2607a8d47072a91fc5ffeea414aad803eb9f\n\n点击授权\n\nPOST /authorize\n  authorize: 1\n  utf8: ✓\n  authenticity_token: \u003cyour token\u003e\n  client_id: 9c16d1d9d4235bb723c4\n  redirect_uri: https://learn.co/users/auth/github/callback\n  state: 7947e14af4fd2607a8d47072a91fc5ffeea414aad803eb9f\n  scope:\n  authorize: 1\n\n调整到回调页面\n\nGET /callback\n  code: 7c91849181a5cc05d777\n  state: 7947e14af4fd2607a8d47072a91fc5ffeea414aad803eb9f\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzce%2Foauth2-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzce%2Foauth2-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzce%2Foauth2-example/lists"}