Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GET https://dribbble.com/oauth/authorize
- window.location.href = https://dribbble.com/oauth/authorize?client_id=clientidhere&redirect_uri=http://localhost:4200/signup?step=three&state=230948lksdjf02384ldskf
- exports.oAuthUserLink = functions.https.onRequest((req, res) => {
- cors(req, res, () => {
- return getAuthToken(req, res, admin, config, otherConfig);
- });
- });
- getAuthToken = function (req, res, admin, fbConfig, config) {
- const rp = require('request-promise');
- const oAuthUrl = 'https://dribbble.com/oauth/token?';
- const code = '&code=' + req.query.code;
- let state = '&state=' + req.query.state;
- const clientId = '?client_id=' + config.dribbble.client_id;
- const secret = '&client_secret=' + config.dribbble.client_secret;
- const options = {
- method: 'POST',
- uri: oAuthUrl + clientId + secret + code + state,
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- };
- rp(options)
- .then(body => {
- const bodyObj = JSON.parse(body);
- console.log('bodyObj', bodyObj)
- });
- }
- {
- "error": "invalid_grant",
- "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."
- }
- exports.redirect = function (req, res, admin) {
- const config = functions.config();
- const rp = require('request-promise');
- const state = req.query.state;
- const userId= req.query.userId;
- const redirectUrl = `https://us-central1-my-test-app.cloudfunctions.net/oAuthUserLink`;
- //here I've changed the redirectUrl from localhost to the endpoint to my function above
- const clientId = config.dribbble.client_id;
- const getToken = {
- uri: `https://dribbble.com/oauth/authorize`,
- qs: {
- client_id: clientId,
- state: state,
- redirect_uri: redirectUrl
- },
- headers: { 'User-Agent': 'Needly Workcoin Market'}
- };
- rp(getToken).then(response => {
- res.send(response); //this response is a 302 redirect to their login page
- });
- }
Add Comment
Please, Sign In to add comment