{"id":30807402,"url":"https://github.com/raycarterlab/auth","last_synced_at":"2025-09-06T02:08:35.159Z","repository":{"id":56619059,"uuid":"301038347","full_name":"RayCarterLab/auth","owner":"RayCarterLab","description":"Python Jwt in Graphql","archived":false,"fork":false,"pushed_at":"2020-10-29T08:22:28.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-12T16:11:46.130Z","etag":null,"topics":["graphql","jwt-token","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","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/RayCarterLab.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-10-04T04:22:13.000Z","updated_at":"2020-10-29T08:22:31.000Z","dependencies_parsed_at":"2022-08-15T22:01:05.099Z","dependency_job_id":null,"html_url":"https://github.com/RayCarterLab/auth","commit_stats":null,"previous_names":["raycarterlab/auth","sundaywindy/auth"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/RayCarterLab/auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayCarterLab%2Fauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayCarterLab%2Fauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayCarterLab%2Fauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayCarterLab%2Fauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RayCarterLab","download_url":"https://codeload.github.com/RayCarterLab/auth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayCarterLab%2Fauth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273847264,"owners_count":25178647,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"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":["graphql","jwt-token","python3"],"created_at":"2025-09-06T02:08:30.314Z","updated_at":"2025-09-06T02:08:35.102Z","avatar_url":"https://github.com/RayCarterLab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 权限验证\n\n ![python3.8](https://img.shields.io/badge/language-python3.8-blue.svg) \u0026nbsp; ![framework](https://img.shields.io/badge/framework-graphql-blue) \u0026nbsp; ![issues](https://img.shields.io/github/issues/RuiCoreSci/auth) ![stars](https://img.shields.io/github/stars/RuiCoreSci/auth) \u0026nbsp; ![license](https://img.shields.io/github/license/RuiCoreSci/auth)\n\n* 此项目是模板项目，使用 PyJwt 进行基本的登录验证。\n* 基于 pyjwt、[ariadne](https://github.com/mirumee/ariadne)、[aioredis](https://github.com/aio-libs/aioredis)、[starlette](https://github.com/encode/starlette)、sqlalchmy 进行开发。\n* 使用 redis 存储 token，token 的有效期为一天，用户可以选择登出，登出即撤销 token。\n\n**目录**\n\n\u003c!-- TOC --\u003e\n\n- [权限验证](#%E6%9D%83%E9%99%90%E9%AA%8C%E8%AF%81)\n    - [认证](#%E8%AE%A4%E8%AF%81)\n    - [授权](#%E6%8E%88%E6%9D%83)\n    - [鉴权](#%E9%89%B4%E6%9D%83)\n\n\u003c!-- /TOC --\u003e\n\n## 认证\n* 认证是指根据声明者所持有的信息，确认声明者的身份，在英文中对应 `identification`。常见的认证方式是【用户名 + 密码】。\n* 此模块对登录的用户进行认证。\n\n```py\nclass Identity:\n    @staticmethod\n    def identity(user_id: int, password: str) -\u003e User:\n```\n* 验证输入的 id【可以替换成任意能唯一标识用户的属性】对应的用户密码和输入的密码是否一致，若一致，返回用户，否则抛出异常。\n\n## 授权\n* 授权是指资源所有者委派资源执行者，赋予执行者指定范围的资源操作权限，在英文中对应 `authorization`。\n* 此模块进行授权，为 user 返回生成的 token。\n```py\n    async def authorize(user: User, device: str = \"pc\", auto_delete=True) -\u003e str:\n    pass\n```\n* authorize 方法接收三个参数，用户 `user`，设备类型 `device`,以及是否主动删除过期 token `auto_delete`。\n\n\n## 鉴权\n* 鉴权是指对于一个声明者所声明的权限，对声明的真实性进行鉴别并确认的过程，在英文中对应 `authentication`。\n* 此模块进行 token 验证，验证 token 是否有效。\n```py\nclass _Authenticate:\n    @staticmethod\n    async def verify(token: str):\n      pass\n```\n* verify 对 token 进行验证，验证 token 是否合法；对于某些设备【比如移动端】，即使 token 超过了有效期，仍然可以认为这个 token 有效；因此 token 有效的规则是：\n\n```py\n1、token 格式合法 \u0026\u0026 token 在 redis 数据库中存在 \u0026\u0026 token 没有过有效期 or\n2、token 格式合法 \u0026\u0026 token 在 redis 数据库中存在 \u0026\u0026 token 过期 \u0026\u0026 token 为指定类型\n```\n\n* 一般来说，这几者之间的关系是 **认证**--\u003e**授权**--\u003e**鉴权**--\u003e**权限控制**（本文未列出）。\n\n\u003c!-- TOC ignore:true --\u003e\n## Maintainers\n\n[@ ruicore](https://github.com/ruicore)\n\n\u003c!-- TOC ignore:true --\u003e\n## Contributing\n\nPRs are accepted.\n\n\u003c!-- TOC ignore:true --\u003e\n## License\n\nMIT © 2020 ruicore\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraycarterlab%2Fauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraycarterlab%2Fauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraycarterlab%2Fauth/lists"}