Advertisement
Guest User

Untitled

a guest
May 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. "bcrypt-nodejs": "0.0.3",
  2. "body-parser": "^1.15.1",
  3. "cors": "^2.7.1",
  4. "express": "~4.1.1",
  5. "firebase": "^3.0.3",
  6. "mongoose": "^4.4.19",
  7. "oauth2orize": "^1.3.0",
  8. "passport": "^0.3.2",
  9. "passport-jwt": "^2.0.0",
  10. "passport-local": "^1.0.0"
  11. "jsonwebtoken": "^7.0.0"
  12.  
  13. {
  14. "error": {
  15. "errors": [
  16. {
  17. "domain": "global",
  18. "reason": "invalid",
  19. "message": "INVALID_CUSTOM_TOKEN"
  20. }
  21. ],
  22. "code": 400,
  23. "message": "INVALID_CUSTOM_TOKEN"
  24. }
  25. }
  26.  
  27. var token = jwt.sign(
  28. {
  29. iss: jwt_config.client_email,
  30. sub: jwt_config.client_email,
  31. aud: 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
  32. iat: iat,
  33. exp: exp,
  34. uid: user._id,
  35. claims: {
  36. username: user.username,
  37. user_id: user._id,
  38. roles: user.role
  39. }
  40. },
  41. jwt_config.private_key,
  42. {
  43. algorithm: 'RS256'
  44. }
  45. );
  46. res.json({success: true, token: token});
  47.  
  48. var jwt_config = require('../config/Firebase-68824d8xxxxx.json');
  49.  
  50. firebase.initializeApp(config);
  51. $.ajax({
  52. type: 'post',
  53. dataType: 'json',
  54. url: 'http://ec2-52...compute.amazonaws.com:3000/api/authenticate',
  55. data: $('#loginForm').serialize(),
  56. complete: function(result) {
  57. result = result.responseJSON;
  58. // console.log(JSON.stringify(result, null, 4));
  59. var success = result.success;
  60. if (success) {
  61. var data = result.token;
  62.  
  63. firebase.auth().signInWithCustomToken(data).catch(function(error) {
  64. // Handle Errors here.
  65. var errorCode = error.code;
  66. var data = error.message;
  67. // ...
  68. });
  69.  
  70. } else {
  71. var data = result.message;
  72. }
  73. $('#token').html(data);
  74. }
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement