Guest User

Untitled

a guest
Apr 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. GET https://dribbble.com/oauth/authorize
  2.  
  3. window.location.href = https://dribbble.com/oauth/authorize?client_id=clientidhere&redirect_uri=http://localhost:4200/signup?step=three&state=230948lksdjf02384ldskf
  4.  
  5. exports.oAuthUserLink = functions.https.onRequest((req, res) => {
  6. cors(req, res, () => {
  7. return getAuthToken(req, res, admin, config, otherConfig);
  8. });
  9. });
  10.  
  11. getAuthToken = function (req, res, admin, fbConfig, config) {
  12. const rp = require('request-promise');
  13.  
  14. const oAuthUrl = 'https://dribbble.com/oauth/token?';
  15. const code = '&code=' + req.query.code;
  16. let state = '&state=' + req.query.state;
  17. const clientId = '?client_id=' + config.dribbble.client_id;
  18. const secret = '&client_secret=' + config.dribbble.client_secret;
  19.  
  20. const options = {
  21. method: 'POST',
  22. uri: oAuthUrl + clientId + secret + code + state,
  23. headers: {
  24. 'Accept': 'application/json',
  25. 'Content-Type': 'application/x-www-form-urlencoded'
  26. }
  27. };
  28.  
  29. rp(options)
  30. .then(body => {
  31. const bodyObj = JSON.parse(body);
  32. console.log('bodyObj', bodyObj)
  33. });
  34.  
  35. }
  36.  
  37. {
  38. "error": "invalid_grant",
  39. "error_description": "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
  40. }
  41.  
  42. exports.redirect = function (req, res, admin) {
  43. const config = functions.config();
  44. const rp = require('request-promise');
  45.  
  46. const state = req.query.state;
  47. const userId= req.query.userId;
  48. const redirectUrl = `https://us-central1-my-test-app.cloudfunctions.net/oAuthUserLink`;
  49. //here I've changed the redirectUrl from localhost to the endpoint to my function above
  50. const clientId = config.dribbble.client_id;
  51.  
  52. const getToken = {
  53. uri: `https://dribbble.com/oauth/authorize`,
  54. qs: {
  55. client_id: clientId,
  56. state: state,
  57. redirect_uri: redirectUrl
  58. },
  59. headers: { 'User-Agent': 'Needly Workcoin Market'}
  60. };
  61.  
  62. rp(getToken).then(response => {
  63. res.send(response); //this response is a 302 redirect to their login page
  64. });
  65. }
Add Comment
Please, Sign In to add comment