As a software developer specializing in backend systems, outline the process of building a RESTful API with user authentication. Provide detailed instructions on setting up the development environment, designing the API endpoints, and implementing authentication protocols such as OAuth or JWT. Discuss security best practices and how to handle common issues like token expiration and user role management. Include code snippets and testing strategies to ensure functionality and security. The output should be a comprehensive guide that developers can follow to implement a secure API in their own projects.