PassportJs Google OAuth2 Strategy error: TokenError: Code was already redeemed - passport.js

I am trying to implement login through google using passport google oauth2 strategy. But I am getting the following error. I searched for solutions but none of them worked for me.
TokenError: Code was already redeemed.
at Strategy.OAuth2Strategy.parseErrorResponse (/home/venkatesh/Documents/Web
Dev/Apps/myapps/user_auth_jwts/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/lib/strategy.js:320:12)
at Strategy.OAuth2Strategy._createOAuthError (/home/venkatesh/Documents/Web
Dev/Apps/myapps/user_auth_jwts/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/lib/strategy.js:367:16)
at /home/venkatesh/Documents/Web Dev/Apps/myapps/user_auth_jwts/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/lib/strategy.js:166:45
at /home/venkatesh/Documents/Web Dev/Apps/myapps/user_auth_jwts/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/home/venkatesh/Documents/Web Dev/Apps/myapps/user_auth_jwts/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:123:9)
at IncomingMessage. (/home/venkatesh/Documents/Web Dev/Apps/myapps/user_auth_jwts/node_modules/passport-google-oauth/node_modules/passport-google-oauth20/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:437:9)
at process._tickCallback (node.js:351:17)

Related

InternalOAuthError discord oauth2

I am trying to log my users in using discord oauth2
I noticed, when clicking the authorize button multiple times, I am getting this error.
InternalOAuthError: Failed to fetch user's guilds
at S:\project\node_modules\passport-discord\lib\strategy.js:108:32
at passBackControl (S:\project\node_modules\oauth\lib\oauth2.js:132:9)
at IncomingMessage.<anonymous> (S:\project\node_modules\oauth\lib\oauth2.js:157:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
After that I also get this error, but idk if that is important:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
I am using passport, passport-discord and express-session
Yes this is because of the rate limit that discord has. I do not know any solution for this beside changing you passport to keep track of the amount of request made to discord.

FetchError while deleting files Google Cloud Storage via Nodejs Firebase functions

I am having a fetchError while trying to delete multiple files in a single bucket. My application requires finding older objects and then deleting any files a user has uploaded to the cloud storage.
So when I loop through files to delete, I seem to get a fetchError when there are too many files to delete.
At first it was working fine(testing phase) but now I notice that I get a fetchError when there is too many files to delete at the same time.
error:
{ FetchError: request to https://storage.googleapis.com/storage/v1/b/bucketName/o/filePath? failed, reason: socket hang up
at ClientRequest.<anonymous> (/srv/node_modules/node-fetch/lib/index.js:1453:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:401:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:66:8)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
message: 'request to https://storage.googleapis.com/storage/v1/b/bucketName/o/filePath? failed, reason: socket hang up',
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET' }
my deleteFunction:
I query a collection, then loop the querysnapshot to get the individual documentsnapshots where I get the image and video filePaths which I pass into deleteFile(myBucketName, mediaFilePath)
const gcs = new Storage();
async function deleteFile(bucketName, fileName) {
await gcs.bucket(bucketName).file(fileName).delete();
}
I am thinking, should I update the meta-data of the images to be deleted and listen in another function for onMetaDataChange for storage and then delete it? Would that be any better?
This doesn't seem to be an issue with Storage or Cloud Functions. Seems to be an issue with your implementation to handle multiple-requests as the error is related to the socket. (Here's is explained better). You can use batch requests or this answer could help you.

Trying to authenticate users with Passport.js and Soundcloud

I am trying to make a web app in NodeJS, that uses passport to authenticate users. I've incorporated Soundcloud in my app on the front end, but would like to add soundcloud authenication in as well. I've tried many packages, and passport-soundcloud is the one that has seemed to work the best. However, somewhere along the line, and the stack trace won't tell me where (location in the passport-soundcloud code), I get this error:
TokenError
at Strategy.OAuth2Strategy.parseErrorResponse (/Users/marisusis/Documents/Repos/visualizer/node_modules/passport-oauth2/lib/strategy.js:329:12)
at Strategy.OAuth2Strategy._createOAuthError (/Users/marisusis/Documents/Repos/visualizer/node_modules/passport-oauth2/lib/strategy.js:376:16)
at /Users/marisusis/Documents/Repos/visualizer/node_modules/passport-oauth2/lib/strategy.js:166:45
at /Users/marisusis/Documents/Repos/visualizer/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/Users/marisusis/Documents/Repos/visualizer/node_modules/oauth/lib/oauth2.js:123:9)
at IncomingMessage.<anonymous> (/Users/marisusis/Documents/Repos/visualizer/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Any ideas on how to fix this, or an alternate package or method I could use?

Using node.js request with lets encrypt "unable to verify the first certificate" error

I am using node-slack to use the Mattermost incoming URL Api for a self hosted mattermost. This mattermost is secured by lets-encrypt.
My node code is working with the slack api, and i have testet the send data with Postman (manual post tool) against the MM server.
In both cases it is working.
But with node i receive a unable to verify the first certificate error.
In "https://nodejs.org/api/https.html" I can see, that node.js is supporting a "well known" set of root CAs.
To simplify the question, I have written this small peace of code:
let request = require('request');
request("https:--letsencryptsecuredsite",function(err,body){
console.log(err);
console.log(body);
});
This results in
{ Error: unable to verify the first certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1079:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:603:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }
What do i have to use an API on a lets encrypt secured server ?
I am using node version 6.9.2.

Socket Hang up while making multiple http post requests

I am reading a csv file and I am extracting data and making a post request every 30 seconds(setTimeout help) with data extracted with request module, after making 3 requests it shows this error
Error: socket hang up
at createHangUpError (_http_client.js:200:15)
at Socket.socketOnEnd (_http_client.js:292:23)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
Depending on your implementation there could be multiple things that could cause this.
I would use something like Async Parallel for these kind of tasks.
Give it a try.

Resources