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

    Calling secure Spring Boot endpoint from JS (react)

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    2
    2
    1.1k
    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.
    • H
      hendrik.ebbers
      last edited by

      Hey,
      I'm currently trying to create a small sample that uses OpenID Connect. My usecase is like that:

      • I have a spring boot server with public and secure endpoints
      • I have a react client

      Based on your really great react (https://fusionauth.io/docs/quickstarts/quickstart-javascript-react-web) and spring (https://fusionauth.io/docs/quickstarts/quickstart-springboot-api) sample I easily got the 2 parts running individually. But now I want to have them in 1 app: Once a user is logged in (in the frontend) he can call a secured endpoint at the spring server.

      My basic fetch call in react looks like that:

      const getSecuredData = () => {
        const response = fetch(
          'http://localhost:8080' + '/api/secured',
          {
            method: 'GET',
            headers: {'Authorization':
                  'Bearer ' + token}
          }
        ).then((response) => response.text())
        .then((data) => console.log(data))
        .catch(reason => alert("Not authenticated"));
      }
      

      The big problem is that I have no idea how to get the token. the react api provides a user but that does not have a token:

      {
      "applicationId": "e9fdb985-9173-4e01-9d73-ac2d60d1dc8e",
      "birthdate": "1985-11-23",
          "email": "richard@example.com",
          "email_verified": true,
          "family_name": "Hendricks",
          "given_name": "Richard",
          "roles": [],
          "scope": "openid offline_access",
          "sid": "0021af21-227b-4374-b84a-55d4a28c22cd",
          "sub": "00000000-0000-0000-0000-111111111111",
          "tid": "d7d09513-a3f5-401c-9685-34ab6c552453"
      }
      
      1 Reply Last reply Reply Quote 0
      • mark.robustelliM
        mark.robustelli
        last edited by mark.robustelli

        @hendrik-ebbers I am a little confused on the ask. It sounds like you want a user to be able to log into a webpage and then be able to call your apis? Would they call the apis from an interface you provide in the web application or from some other application?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post