{"id":15097891,"url":"https://github.com/durban89/koa-oauth-server","last_synced_at":"2025-10-08T02:31:58.138Z","repository":{"id":34315145,"uuid":"38232749","full_name":"durban89/koa-oauth-server","owner":"durban89","description":"Complete, compliant and well tested module for implementing an OAuth2 Server/Provider with koa in node.js","archived":false,"fork":true,"pushed_at":"2015-07-07T11:52:23.000Z","size":127,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-16T16:10:04.031Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"oauthjs/koa-oauth-server","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/durban89.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","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":"2015-06-29T07:05:05.000Z","updated_at":"2016-03-10T15:24:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/durban89/koa-oauth-server","commit_stats":null,"previous_names":["zhangda89/koa-oauth-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/durban89%2Fkoa-oauth-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/durban89%2Fkoa-oauth-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/durban89%2Fkoa-oauth-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/durban89%2Fkoa-oauth-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/durban89","download_url":"https://codeload.github.com/durban89/koa-oauth-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235674061,"owners_count":19027515,"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-25T16:41:07.914Z","updated_at":"2025-10-08T02:31:52.345Z","avatar_url":"https://github.com/durban89.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-gowhich\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-gowhich');\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-gowhich');\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%2Fdurban89%2Fkoa-oauth-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdurban89%2Fkoa-oauth-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdurban89%2Fkoa-oauth-server/lists"}