Skip to content
Advertisement

How do I get the current user’s id in this Laravel 8 and Auth0 API?

I am working on a Laravel 8 API. I use Auth0 for user registration and login.

At registration, I need the user’s id returned by Auth0 (as user_id), in order to insert it into my own users table, in a column called uid.

Also, once a user is logged in, I need to display the user’s data at myapp.test/api/user-profile/show/ for which, also, I need the user_id.

For this purpose I have the code:

In routesapi.php:

JavaScript

In the UserController:

JavaScript

The problem

The authorize() method (taken from a tutorial on the Auth0 website), only returns the access_token info but not the user_id.

Questions

  1. How do I get the current user’s user_id?
  2. I suppose I need to replace CURLOPT_URL => "$appDomain/oauth/token" with something, not with what?

Advertisement

Answer

Please look at this community answer:

https://community.auth0.com/t/how-to-get-user-information-from-the-laravel-api-side/47021/3

Make a request to the Authentication API’s userinfo endpoint to get the user’s profile. https://auth0.com/docs/api/authentication#user-profile

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement