FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Express-React Example App on vServer

    Scheduled Pinned Locked Moved Solved
    Q&A
    1
    2
    350
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fritzgaertner
      last edited by

      Hey FusionAuth Community,

      in the last few days I installed a docker image of fusionauth on my vserver, set everything up and made a new application.
      After that I used this tutorial:
      https://fusionauth.io/blog/2020/03/10/securely-implement-oauth-in-react
      to build a React-Express App. I made a few changes like serving the react app in a static way over the public folder, so it can run on my vServer without problems.

      Everything worked just fine and you can visit the app on http://login.ruffyg.de/

      But when I try to login with the right credentials my page redirects me to

      http://login.ruffyg.de/oauth-callback?code=8LS2k9VlXp43j-C7NGXKy9n_X3a9GA0jSIeKrBDUxeU&locale=de_DE&userState=Authenticated (<- I changed a few letters for security reasons)

      Normally it should redirect me to my react app, right? My oauth-callback.js looks like this...

      const express = require('express');
      const router = express.Router();
      const request = require('request');
      const config = require('../../config');
      
      router.get('/', (req, res) => {
        request(
          // POST request to /token endpoint
          {
            method: 'POST',
            uri: `http://login.ruffyg.de:${config.fusionAuthPort}/oauth2/token`,
            form: {
              'client_id': config.clientID,
              'client_secret': config.clientSecret,
              'code': req.query.code,
              'code_verifier': req.session.verifier,
              'grant_type': 'authorization_code',
              'redirect_uri': config.redirectURI
            }
          },
      
          // callback
          (error, response, body) => {
            // save token to session
            req.session.token = JSON.parse(body).access_token;
      
            // redirect to the React app
            res.redirect(`http://login.ruffyg.de:${config.clientPort}`);
          }
        );
      });
      
      module.exports = router;
      
      
      1 Reply Last reply Reply Quote 0
      • F
        fritzgaertner
        last edited by

        Fixed the problem on my own, for everyone running into this problem too. Check your redirect uri in config.js and your fusionauth dashboard.

        In my case I got redirected to:

        http://login.ruffyg.de/oauth-callback?...........

        but of course it has to redirect to my express server which is on port 9000 so:

        http://login.ruffyg.de:9000/oauth-callback?...........

        1 Reply Last reply Reply Quote 0
        • F fritzgaertner has marked this topic as solved on
        • First post
          Last post