May 1, 2020

I went digging through the Passport.js code to get a better understanding of what’s happening under the hood. In doing so, I discovered that passport.js handles state. That’s fantastic. It appears that passport-oauth2 handles just about everything, including capturing the incoming access code from the url. I just have to figure out the routing to make sure that the incoming and outgoing information is handled correctly. It always seems to come back to routing.

Routing routing routing. Instead of using a separate route for auth, I tried implementing the routes directly in the bin/www file, but this did not work as I hoped.

I then refactored the code to bypass auth.js and placed the routing for /auth directly in the file where the server middleware and routes are set up. This, however, has a few problems, from what I determine: first, there is a “Cannot GET /auth” error appearing in the browser upon redirect from discord; second, there is no state key being defined, despite setting this property to “true” in the OAuth2Strategy object. I’m missing some major conceptual information to the routing working properly.

At one point, I was being redirected back home to indicate that authentication failed. I’m not sure what the issue was at that point, but I have a suspicion that the identifying credentials I’m supposed to send over to Discord are not actually being sent. Considering this, I started playing with various POST and GET configurations in the routing, none of which have worked. I feel completely lost as to what I’m doing wrong in this process, and it’s becoming frustrating.

Comments? Follow me on twitter and drop me a line in response to this tweet:

Day 015: more routing shenanigans in express. I swear I’m missing something really fundamental, and it’s starting to become frustrating. https://t.co/3X2GuzcFyc#nonsensemod365 #thatCodingLife pic.twitter.com/Cjz2uEx2n5

— Joshua Alexander (@nonsensecodes) May 1, 2020