Accessing user data

Now that we set up authentication, let's create an endpoint that returns the user's ID as a response by reading it from user claims.

Create a UsersController in the Controllers folder and change the class to the following:

UsersController.cs
public class UsersController : Controller
{
    [Authorize]
    public IActionResult UserData()
    {
        return Ok(new
        {
            UserId = User.Claims.FirstOrDefault(c => c.Type == "urn:roblox:id").Value
        });
    }
}

The above code snippet

  • Requires authentication on the /users/userdata endpoint

  • Reads the user ID as a claim of type urn:roblox:id

  • Returns an object containing the user ID

Now when an authenticated user navigates to /users/userdata they will receive an object containing their Roblox user ID as a response.

Last updated

Was this helpful?