MERN Authentication?

Hi Friends,

I’m fairly new to web development. Currently working on an app with mongo/mongoose, express, react, and node. I’d like to allow users to login via twitch. Then provide data based on what the user authorizes to share. I’m just having a difficult time with that javascript setup. I’m able to follow the twitch documentation up until the ‘curl’ line, so not very far. I’m not sure what curl is. The syntax that follows also looks different than what I’m used to.

Would someone be able to provide a skeleton or another resource for a js setup?

Thank you for the help

CURL is basically a HTTP request.

As an example of the OAuth Authorization code flow you will redirect the user to https://id.twitch.tv/oauth2/authorize?client_id=<your client ID>&redirect_uri=<your registered redirect URI>&response_type=code&scope=<space-separated list of scopes>

This’ll send the user to Twitch and ask them if they want to authorize your app, if they do they’ll be redirect back to the redirect URL you’ve set along with a code parameter in the querystring, eg https://<your registered redirect URI>/?code=<authorization code>.

Using that code you’ll make a HTTP POST request like https://id.twitch.tv/oauth2/token?client_id=<your client ID>&client_secret=<your client secret>&code=<authorization code received above>&grant_type=authorization_code&redirect_uri=<your registered redirect URI>

Twitch will respond to that POST request with a reply containing the access token, refresh token, expiration etc… for you to do what you intend to do with. At this point the user has connected to your app and if you’re using it as a way to login to your site you’ll likely want to create a session for that user and store the tokens in your database.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.