{"id":15046537,"url":"https://github.com/oauthjs/koa-oauth-server","last_synced_at":"2025-07-17T14:06:59.783Z","repository":{"id":13309930,"uuid":"15996397","full_name":"oauthjs/koa-oauth-server","owner":"oauthjs","description":"Complete, compliant and well tested module for implementing an OAuth2 Server/Provider with koa in node.js","archived":false,"fork":false,"pushed_at":"2021-07-28T07:00:56.000Z","size":59,"stargazers_count":213,"open_issues_count":21,"forks_count":80,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-29T23:17:18.766Z","etag":null,"topics":[],"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/oauthjs.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","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":"2014-01-17T10:10:16.000Z","updated_at":"2025-01-18T14:31:53.000Z","dependencies_parsed_at":"2022-09-11T06:21:46.848Z","dependency_job_id":null,"html_url":"https://github.com/oauthjs/koa-oauth-server","commit_stats":null,"previous_names":["thomseddon/koa-oauth-server"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/oauthjs/koa-oauth-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauthjs%2Fkoa-oauth-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauthjs%2Fkoa-oauth-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauthjs%2Fkoa-oauth-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauthjs%2Fkoa-oauth-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oauthjs","download_url":"https://codeload.github.com/oauthjs/koa-oauth-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauthjs%2Fkoa-oauth-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265614332,"owners_count":23798427,"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-09-24T20:53:13.150Z","updated_at":"2025-07-17T14:06:59.759Z","avatar_url":"https://github.com/oauthjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Koa OAuth Server [![Build Status](https://travis-ci.org/thomseddon/koa-oauth-server.png?branch=master)](https://travis-ci.org/thomseddon/koa-oauth-server)\n\nComplete, compliant and well tested module for implementing an OAuth2 Server/Provider with [koa](https://github.com/koajs/koa) in [node.js](http://nodejs.org/).\n\nThis is the koa wrapper for [oauth2-server](https://github.com/thomseddon/node-oauth2-server).\n\n## Installation\n\n    $ npm install koa-oauth-server\n\n## Quick Start\n\nThe module provides two middlewares - one for granting tokens and another to authorise them. `koa-oauth-server` and, consequently `oauth2-server`, expect the request body to be parsed already.\nThe following example uses `koa-bodyparser` but you may opt for an alternative library.\n\n```js\nvar koa = require('koa');\nvar bodyparser = require('koa-bodyparser');\nvar oauthserver = require('koa-oauth-server');\n\nvar app = koa();\n\napp.oauth = oauthserver({\n  model: {}, // See https://github.com/thomseddon/node-oauth2-server for specification\n  grants: ['password'],\n  debug: true\n});\n\napp.use(bodyparser());\napp.use(app.oauth.authorise());\n\napp.use(function *(next) {\n  this.body = 'Secret area';\n  yield next;\n});\n\napp.listen(3000);\n```\n\n### Using `koa-router` with `koa-mount`\n\nIf you wish to integrate with `koa-router` using `koa-mount`, you may do so by combining them to mount a specific prefix for oauth operations:\n\n```js\nvar Router = require('koa-router');\nvar bodyparser = require('koa-bodyparser');\nvar koa = require('koa');\nvar model = require('koa-oauth-server/node_modules/oauth2-server/examples/memory/model');\nvar mount = require('koa-mount');\nvar oauthserver = require('koa-oauth-server');\n\n// Create a new koa app.\nvar app = koa();\n\n// Create a router for oauth.\nvar router = new Router();\n\n// Enable body parsing.\napp.use(bodyparser());\n\n// See https://github.com/thomseddon/node-oauth2-server for specification.\napp.oauth = oauthserver({\n  model: model,\n  grants: ['password'],\n  debug: true\n});\n\n// Mount `oauth2` route prefix.\napp.use(mount('/oauth2', router.middleware()));\n\n// Register `/token` POST path on oauth router (i.e. `/oauth2/token`).\nrouter.post('/token', app.oauth.grant());\n\n// Start koa server.\napp.listen(3000);\n```\n\nThen attempt to be granted a new oauth token:\n\n```sh\ncurl -XPOST -d 'username=thomseddon\u0026password=nightworld\u0026grant_type=password\u0026client_id=thom\u0026client_secret=nightworld' http://localhost:3000/oauth2/token\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foauthjs%2Fkoa-oauth-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foauthjs%2Fkoa-oauth-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foauthjs%2Fkoa-oauth-server/lists"}