Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. //Policies
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7.  
  8. module.exports = function(req, res, next) {
  9.  
  10. // User is allowed, proceed to the next policy,
  11. // or if this is the last policy, the controller
  12. if (req.header("Authorization")) {
  13.  
  14.  
  15. var auth = req.header("Authorization");
  16. var tmp = auth.split(' '); // Split on a space, the original auth looks like "Basic Y2hhcmxlczoxMjM0NQ==" and we need the 2nd part
  17. var buf = new Buffer(tmp[1], 'base64'); // create a buffer and tell it the data coming in is base64
  18. var plain_auth = buf.toString(); // read it back out as a string
  19.  
  20. var creds = plain_auth.split(':'); // split on a ':'
  21. var username = creds[0];
  22. var password = creds[1];
  23. var url = req.host;
  24.  
  25. return Oauth2ClientCredentialService.validateClientCredentials(username, password, url)
  26. .then(function(result){
  27. next(result);
  28. }).catch(function(err){
  29. next("You are not permitted to perform this action.haahahahahahahh");
  30. });
  31.  
  32. }
  33. // User is not allowed
  34. // (default res.forbidden() behavior can be overridden in `config/403.js`)
  35. return res.forbidden('You are not permitted to perform this action.');
  36.  
  37. };
  38.  
  39.  
  40. //RESPONSE HEADER
  41.  
  42. 500 Internal Server Error
  43.  
  44. //RESPONSE BODY:
  45.  
  46. {
  47. "url": "127.0.0.1",
  48. "clientid": "blahblah",
  49. "clientpassword": "blahblah",
  50. "email": "BLAH811@gmail.com",
  51. "createdAt": "2017-04-24T05:10:46.996Z",
  52. "updatedAt": "2017-04-24T05:10:46.996Z",
  53. "id": "58fd88d6e345fd2b1da4bda1"
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement