How to obtain the user information from the Access Token in Rails

Hello, in this example I am using Node.js to send from my backend the information from the user and I am also printing in the console the token I am getting from the front end

Now the issue I have I that I am trying to replicate the same thing but using rails,
here is the configuration inside my App.js

import React from 'react';
import './App.css';
import { useAuth0 } from '@auth0/auth0-react';
import axios from 'axios';

function App() {
  const {
    loginWithPopup,
    loginWithRedirect,
    logout,
    user,
    isAuthenticated,
    getAccessTokenSilently,
  } = useAuth0();


  const callApi = async () => {
    try {
      const response = await axios.get('http://localhost:5000');
      console.log(response.data);
    } catch (error) {
      console.error(error);
    }
  };

  const callProtectedApi = async () => {
    try {
      const token = await getAccessTokenSilently();
      const response = await axios.get('http://localhost:5000/private', {
        headers: {
          authorization: `Bearer ${token}`,
        },
      });
      console.log(response.data);
    } catch (error) {
      console.log(error.messsage);
    }
  };
  return (
    <div className="App">
      <h1>Auth0 authentication</h1>
      <ul>
        <li>
          <button onClick={loginWithPopup}>Login with Popup</button>
          <button onClick={loginWithRedirect}>Login with Redicrect</button>
          <button onClick={logout}>Logout</button>
        </li>
      </ul>
      <h3>User is {isAuthenticated ? 'Logged in' : 'Not logged in'}</h3>
      <ul>
        <li>
          <button onClick={callApi}>Call API</button>
        </li>
        <li>
          <button onClick={callProtectedApi}>Call Proteced API route </button>
        </li>
      </ul>
      <pre style={{ textAlign: 'start' }}>{JSON.stringify(user, null, 2)}</pre>
    </div>
  );
}

export default App;

now inside my rails app, I have added the examples from the tutorial to configure API and validate token, matter a fact I get the following results

now what i am trying to do is show replicate the same thing I did with Node.js I want to send back to the front end the credentials of the user that logged in.
I was trying to add the following code but

class DisplayController < ActionController::API
  def index
    require 'uri'
    require 'net/http'
    require 'openssl'

    url = URI('https://dev-v88tfgqc.us.auth0.com/oauth/token')

    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    request = Net::HTTP::Post.new(url)
    request['content-type'] = 'application/x-www-form-urlencoded'
    request.body = 'grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=Rails.application.credentials.CLIENT_SECRET&audience=Rails.application.credentials.API_IDENTIFIER'

    response = http.request(request)
    puts response.read_body
  end
end

but here is the result i get

I know my environmental variables work because i tested them inside the rails console

I was finally able to get my access token


but what I am still struggling with is how to send back the information of the user once the token is decoded.
Any idea on how I can do that. The reason why I need it is that on the project I am working I am going to use the user information to create a new user in my database, this way I can associate expenses to only that particular user.
So how do I do it?

Hello, can someone please give me a hand, I am trying to retrieve the user information from the back end using rails, I have already achieve this same steps but using node.js
here is the screenshot of what I am trying to accomplish
using node.js I am able to print in the console and on my server the information from the user once is authenticated

now here is where I am have the problem I am trying to accomplish the same thing using rails. Because the project I am working on I was asked to use rails.
what I was able to create was a method to replicate the same thing in node.js


but as you can see on the rails server I can print the token but the status is 401 i don’t know why if i have already retrieved the token and last is because i am not authorized i can’t retrieve the user info as i did on node.js
Please I need help on this, I have been searching and reading for the last 2 days for a way to come up with the solution, and I need to finish this project like if my life depends on it.
Please forgive my ignorance and thanks in advance.

Can you send me your file/github ?

Hi sorry for the late reply!

Can you try changing your Faraday headers to:

{ 'authorization' => "Bearer #{access_token}" }

I think the error might be the missing space between ‘Bearer’ and the token

Let me know if it works!