{"id":13799778,"url":"https://github.com/jchannon/koa-statelessauth","last_synced_at":"2025-10-25T00:03:09.004Z","repository":{"id":19749094,"uuid":"23006041","full_name":"jchannon/koa-statelessauth","owner":"jchannon","description":null,"archived":false,"fork":false,"pushed_at":"2015-10-21T15:45:59.000Z","size":234,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-01T07:31:43.293Z","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/jchannon.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":"2014-08-15T23:23:53.000Z","updated_at":"2017-05-29T16:36:08.000Z","dependencies_parsed_at":"2022-07-22T13:02:04.820Z","dependency_job_id":null,"html_url":"https://github.com/jchannon/koa-statelessauth","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/jchannon%2Fkoa-statelessauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchannon%2Fkoa-statelessauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchannon%2Fkoa-statelessauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchannon%2Fkoa-statelessauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchannon","download_url":"https://codeload.github.com/jchannon/koa-statelessauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238536079,"owners_count":19488650,"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":[],"created_at":"2024-08-04T00:01:06.011Z","updated_at":"2025-10-25T00:03:08.989Z","avatar_url":"https://github.com/jchannon.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"#Koa StatelessAuth\n\nThis is a stateless auth library for `koa`.  If there is no `Authorization` header or if is empty it will return `401` status code.  The library accepts a validator object with a `validate` function. Pass in your own object to determine how it validates.  If the validator does not return a `user` object a 401 is returned;  You can also pass in an optional `options` object that can define paths to ignore and therefore `yield` to the next function without validating the request.\n\n##Usage\n\n```\nvar statelessauth = require('statelessauth');\n\nvar validator = {\n    validate: function (token) {\n        //This should go to a DB etc to get your user based on token\n        if (token === '123') {\n            return;\n        }\n        return {\n            \"name\": \"bob\",\n            \"role\": \"admin\",\n            \"email\": \"bob@acme.com\"\n        };\n    }\n};\n\nvar statelessauthOptions = {\n    ignorePaths: [\"/\", \"/nonsecure\"]\n};\n\napp.use(statelessauth(validator, statelessauthOptions));\n\napp.use(function * (next) {\n    if (this.user) {\n        console.log(this.user.name);\n        console.log(this.user.email);\n        console.log(this.user.role);\n    }\n    yield next;\n});\n```\n\n##statelessauthOptions\n\n* __ignorePaths:__ ( default: *[]* ) Array of Paths, that are ignored by the Authentification.\n* __verbose:__ ( default: *false* ) Show verbose consolelogs if true.\n\n\n\n##TODO\nAllow passthrough for cookie type authentication\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchannon%2Fkoa-statelessauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchannon%2Fkoa-statelessauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchannon%2Fkoa-statelessauth/lists"}