{"id":16485217,"url":"https://github.com/single9/oauth2-pgsql","last_synced_at":"2026-06-08T01:01:47.305Z","repository":{"id":42734168,"uuid":"283238010","full_name":"single9/oauth2-pgsql","owner":"single9","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-13T10:02:42.000Z","size":16831,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T00:11:39.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/single9.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}},"created_at":"2020-07-28T14:33:07.000Z","updated_at":"2021-02-24T01:45:21.000Z","dependencies_parsed_at":"2023-01-28T10:45:16.951Z","dependency_job_id":null,"html_url":"https://github.com/single9/oauth2-pgsql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/single9/oauth2-pgsql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/single9%2Foauth2-pgsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/single9%2Foauth2-pgsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/single9%2Foauth2-pgsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/single9%2Foauth2-pgsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/single9","download_url":"https://codeload.github.com/single9/oauth2-pgsql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/single9%2Foauth2-pgsql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34043822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-07T02:00:07.652Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-11T13:24:45.318Z","updated_at":"2026-06-08T01:01:47.287Z","avatar_url":"https://github.com/single9.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"OAuth2 with PostgreSQL\n======================\n\n主要使用技術\n----------\n\n- Express.js\n- PostgreSQL\n- Nunjucks\n\n安裝\n---\n\n    npm install\n\n    docker-compose up -d\n    npm run setup\n\n執行\n---\n\n    GOOGLE_CLIENT_ID=\u003cGOOGLE_CLIENT_ID\u003e \\\n    GOOGLE_CLIENT_SECRET=\u003cGOOGLE_CLIENT_SECRET\u003e \\\n    FACEBOOK_CLIENT_ID=\u003cFACEBOOK_CLIENT_ID\u003e \\\n    FACEBOOK_CLIENT_SECRET=\u003cFACEBOOK_CLIENT_SECRET\u003e \\\n    npm start\n\n授權流程\n=======\n\nAuthorization Code Grant\n------------------------\n\nlink: https://oauth2-server.readthedocs.io/en/latest/model/overview.html#authorization-code-grant\n\n```text\ngenerateAccessToken(client, user, scope, [callback])\ngenerateRefreshToken(client, user, scope, [callback])\ngenerateAuthorizationCode(client, user, scope, [callback])\n*getAuthorizationCode(authorizationCode, [callback])\n*getClient(clientId, clientSecret, [callback])\n*saveToken(token, client, user, [callback])\n*saveAuthorizationCode(code, client, user, [callback])\n*revokeAuthorizationCode(code, [callback])\nvalidateScope(user, client, scope, [callback])\n```\n\t\n\u003e *必備的 Function\n\n### Flow\n\n```text\n-\u003e *getClient (1st, get client data from db)\n-\u003e generateAuthorizationCode\n-\u003e *saveAuthorizationCode\n-\u003e *getClient (2nd)\n-\u003e *getAuthorizationCode\n-\u003e *revokeAuthorizationCode (Authorization Code 的任務完成)\n-\u003e validateScope (驗證使用者範疇)\n-\u003e *saveToken (儲存 token)\n```\n\t\nRefresh Token\n-------------\n\n### Params\n\n- client_id: Your client id\n- client_secret: Your client secret\n- refresh_token: Your refresh token\n- grant_type: refresh_token\n\n### Flow\n\n```text\n-\u003e *getClient\n-\u003e *getRefreshToken\n-\u003e generateRefreshToken\n-\u003e *saveToken\n```\n\nPassword\n------------------------\n\n### Params\n\n- username: Your username\n- password: Your password\n- client_id: Your client id\n- client_secret: Your client secret\n- grant_type: password\n\n### Flow\n\n```text\n-\u003e *getClient\n-\u003e *getUSer\n-\u003e validateScope\n-\u003e *saveToken\n```\n\nClient Credentials Grant\n------------------------\n\n### params\n\n- client_id: Your client id\n- client_secret: Your client secret\n- grant_type: client_credentials\n\n### Flow\n\n```text\n-\u003e *getClient\n-\u003e *getUserFromClient\n-\u003e validateScope\n-\u003e *saveToken\n```\n\n授權\n===========\n\n1. 藉由上面的各種方式取得 Access Token\n2. 做資料操作時，在 Header 加入授權資訊\n\n```\nAuthorization: Bearer \u003cAccrss Token\u003e\n```\n\n3. 授權驗證無問題的話就會看到資料了\n\n**目前 Access Token 預設存活 15 分鐘**\n\n4. 社群帳號登入機制為登入即註冊\n5. 帳號機制採用 Email 作為 Primary Key，無論何種登入方式，只要 Email 對了就可以登入。\n\nTODO\n====\n\n- [x] 實作 OAuth2 基本功能\n- [x] 使用 DB 儲存 token, code\n- [x] 設計與建立 User 資料表\n- [x] 使 Clinet 與 User 有關聯\n- [x] 使 Token 與 User 和 Client 有關聯\n- [X] 使用者註冊畫面\n- [X] Google, Facebook 登入註冊串接\n- [X] 使用者登入畫面\n- [X] 使用者個人管理畫面\n- [ ] OAuth2 串接應用範例\n- [ ] 伺服器整體儀表板畫面\n- [ ] 逾期 Token, Auth Code 清除機制\n- [X] 伺服器部署腳本\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsingle9%2Foauth2-pgsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsingle9%2Foauth2-pgsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsingle9%2Foauth2-pgsql/lists"}