I'm really stumped on this one, so any help or pointers would be most welcome. I'm following this documentation:
https://www.patreon.com/platform/documentation/oauth
I ran through all the necessary calls in Postman and have got access to the API. Then when I tried to run it through a Node.js / Express app and I started to get the following response as soon as I used the single use token (Step 3 in the referred documentation):
{
"error": "access_denied"
}
I then took the single use code that was being sent to my app and pasted it into the params in Postman and I got the same result (a 401 error). Only when I changed the redirect_url to a php script (on a remote server) and then used that single use code with postman did I get a 200 response.
The following ...
www.patreon.com/oauth2/authorize?response_type=code&client_id=###&redirect_uri=http://www.somesite.com/script.php
... gives me a working code and ...
www.patreon.com/oauth2/authorize?response_type=code&client_id=#####&redirect_uri=http://localhost.com
goves me a code that doesn't work.
I am making both the subsequent calls for the oauth token from Postman so I am a bit lost as to why this is happening.
I am very new to Node.js and Express but I have worked with oauth and api's in general for some time.
Things I have tried:
- Using a url shortner for the redirect url
- using dotted quad instead of localhost
Thanks in advance,
roscminni
EDIT:
Here is the node code that is receiving the redirect
var express = require('express');
var router = express.Router();
router.route('/valid').get(function(req, res){
console.log("CODE");
console.log(req.query.code);
res.redirect("http://google.com");
});
And here's the app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var valid = require('./routes/valid');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(session({
secret: 'keyboard cat'
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/valid',valid);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;