turbob
December 16, 2016, 6:11pm
1
Hello,
Running this code:
Google.requestCredential({
requestPermissions:['https://www.googleapis.com/auth/calendar']
},function(){console.log(arguments)})
Brings up the right popup window where google asks for me to approve logging in. Then it redirects to the right url
https://accounts.google.com/o/oauth2/auth?response_type=code&...
But the screen is just blank. If i copy the url and paste it into another window, it says login worked like it should with a link to close. However I get this error on the server: Error in OAuth Server: Failed to complete OAuth handshake with Google. failed [400] { "error" : "invalid_grant", "error_description" : "Code was already redeemed." }
Why doesn’t the popup work? I am on 1.3.2 and am using windows subsystem for linux
Thanks for the help!
turbob
December 16, 2016, 7:23pm
3
Well I wrote my own oauth, thanks to this great guide: https://aaronparecki.com/2012/07/29/2/oauth2-simplified
var version = 1;
WebApp.connectHandlers.use(`/api/v${version}/google-oauth`, function (req, res, next) {
console.log("BOBBY")
try {
var Fiber = Npm.require('fibers');
console.log("got fiber")
Fiber(function (self) {
var redirectUrl = encodeURIComponent("http://localhost:3000/api/v1/confirm-oauth?provider=google");
var link = `https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=${googleOauthClientId}&redirect_uri=${redirectUrl}&scope=https://www.googleapis.com/auth/calendar`
console.log(link)
res.writeHead(302, {
'Location': link
});
res.end();
}).run();
console.log('fibo')
}
catch (e) {
console.trace(e)
} finally {
}
});
WebApp.connectHandlers.use(`/api/v${version}/confirm-oauth`, function (req, res, next) {
try {
var Fiber = Npm.require('fibers');
Fiber(function (self) {
console.log(req.query);
//CODE - what we are looking for!
var code = req.query.code;
res.write("verified!");
res.end();
}).run();
}
catch (e) {
} finally {
}
})
Mine did that but it sorted itself out after 15 minutes, probably providers updating the redirect uris taking awhile.
turbob
December 23, 2016, 12:03am
5
Thanks for the info. I think it also may have had to do with the fact that I was using a subdomain.