Socket
Socket
Sign inDemoInstall

koa-oauth-server

Package Overview
Dependencies
4
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

test.js

2

index.js

@@ -77,3 +77,3 @@ /**

this.response.jsonp = function (body) {
this.body = JSON.stringify(body);
this.body = body;
};

@@ -80,0 +80,0 @@

{
"name": "koa-oauth-server",
"version": "1.0.0",
"version": "1.0.1",
"description": "OAuth provider for koa",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -39,1 +39,45 @@ # Koa OAuth Server [![Build Status](https://travis-ci.org/thomseddon/koa-oauth-server.png?branch=master)](https://travis-ci.org/thomseddon/koa-oauth-server)

```
### Using `koa-router` with `koa-mount`
If 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:
```js
var Router = require('koa-router');
var bodyparser = require('koa-bodyparser');
var koa = require('koa');
var model = require('koa-oauth-server/node_modules/oauth2-server/examples/memory/model');
var mount = require('koa-mount');
var oauthserver = require('koa-oauth-server');
// Create a new koa app.
var app = koa();
// Create a router for oauth.
var router = new Router();
// Enable body parsing.
app.use(bodyparser());
// See https://github.com/thomseddon/node-oauth2-server for specification.
app.oauth = oauthserver({
model: model,
grants: ['password'],
debug: true
});
// Mount `oauth2` route prefix.
app.use(mount('/oauth2', router.middleware()));
// Register `/token` POST path on oauth router (i.e. `/oauth2/token`).
router.post('/token', app.oauth.grant());
// Start koa server.
app.listen(3000);
```
Then attempt to be granted a new oauth token:
```sh
curl -XPOST -d 'username=thomseddon&password=nightworld&grant_type=password&client_id=thom&client_secret=nightworld' http://localhost:3000/oauth2/token
```

@@ -377,2 +377,29 @@ /**

describe('issue access token', function () {
it('should return `Content-Type` application/json', function (done) {
var app = bootstrap({
model: {
getClient: function (id, secret, callback) {
callback(false, { clientId: 'thom' });
},
grantTypeAllowed: function (clientId, grantType, callback) {
callback(false, true);
},
getUser: function (uname, pword, callback) {
callback(false, { id: 1 });
},
saveAccessToken: function (token, clientId, expires, user, cb) {
cb();
}
},
grants: ['password']
});
request(app.listen())
.post('/oauth/token')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send(validBody)
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8', done);
});
it('should return an oauth compatible response', function (done) {

@@ -379,0 +406,0 @@ var app = bootstrap({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc