Created
April 24, 2017 07:01
-
-
Save dclarke-modus/37b8e34664c9334be20d3795b17c1bfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Policies | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
module.exports = function(req, res, next) { | |
// User is allowed, proceed to the next policy, | |
// or if this is the last policy, the controller | |
if (req.header("Authorization")) { | |
var auth = req.header("Authorization"); | |
var tmp = auth.split(' '); // Split on a space, the original auth looks like "Basic Y2hhcmxlczoxMjM0NQ==" and we need the 2nd part | |
var buf = new Buffer(tmp[1], 'base64'); // create a buffer and tell it the data coming in is base64 | |
var plain_auth = buf.toString(); // read it back out as a string | |
var creds = plain_auth.split(':'); // split on a ':' | |
var username = creds[0]; | |
var password = creds[1]; | |
var url = req.host; | |
return Oauth2ClientCredentialService.validateClientCredentials(username, password, url) | |
.then(function(result){ | |
next(result); | |
}).catch(function(err){ | |
next("You are not permitted to perform this action.haahahahahahahh"); | |
}); | |
} | |
// User is not allowed | |
// (default res.forbidden() behavior can be overridden in `config/403.js`) | |
return res.forbidden('You are not permitted to perform this action.'); | |
}; | |
//RESPONSE HEADER | |
500 Internal Server Error | |
//RESPONSE BODY: | |
{ | |
"url": "127.0.0.1", | |
"clientid": "blahblah", | |
"clientpassword": "blahblah", | |
"email": "[email protected]", | |
"createdAt": "2017-04-24T05:10:46.996Z", | |
"updatedAt": "2017-04-24T05:10:46.996Z", | |
"id": "58fd88d6e345fd2b1da4bda1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment