Backend built with ASP.net 10 with sqlite db, implementing robust authentication via JWT and Google OAuth. It is designed to be secure, fast crud tasks, and easy to integrate with modern frontends like Next.js.
Same project in other backend Python:
POST /api/register: Register new users.POST /api/login: Log in with username/password.
GET /api/login/google: Starts the Google flow.GET /authorize/google: Callback that processes Google's response.POST /api/auth/google/exchange: Exchanges the temporary code for a JWT token.
GET /api/user/profile: Returns the current user's profile.GET /api/protected: Test endpoint to verify authorization.GET /api/stats: Basic system statistics.
- Hashing: Direct use of
bcryptto avoid compatibility issues.
- JWT Authentication: Traditional login and registration with username/password
- OAuth 2.0 Authentication: Login with Google
- .NET 10 - Web API framework
- Sqlite - Database
-
.NET 10 SDK
-
PowerShell (for Windows)
- Clone the repository:
git clone <repository-url>
cd <repository-url>- Edit the
run-with-env.ps1file with your own credentials.
powershell -ExecutionPolicy Bypass -File .\run-with-env.ps1 dotnet ef migrations add InitialCreate dotnet ef database update- Configure environment variables
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API (or the Google People API for modern apps)
- Go to "Credentials" > "Create credentials" > "OAuth 2.0 Client ID"
- Configure:
- Application type: Web application
- Authorized redirect URIs:
http://localhost:5205/authorize/googleandhttp://127.0.0.1:5205/authorize/google
- Copy the Client ID and Client Secret to your
appsettings.jsonorrun-with-env.ps1file
Create Google Console Project and enable the API:
The API will be available at http://localhost:5205
dotnet new webapi -n TaskGo --use-controllers dotnet run dotnet buildsearch packages or libraries in nuget
Registers a new user.
Request Body:
{
"username": "user@example.com",
"password": "password123"
}Response (201):
{
"message": "User registered successfully",
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"user": {
"id": 1,
"username": "user@example.com"
}
}Logs in with username and password.
Request Body:
{
"username": "user@example.com",
"password": "password123"
}Response (200):
{
"message": "Login successful",
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"user": {
"id": 1,
"username": "user@example.com"
}
}Starts the Google authentication process. Redirects the user to Google for authorization.
Google OAuth callback. Redirects the frontend with a temporary authorization code.
Protected route that requires a valid JWT token.
Headers:
Authorization: Bearer <token>
Response (200):
{
"message": "Access authorized",
"user": {
"id": 1,
"username": "user@example.com"
}
}Retrieves the profile of the authenticated user.
Headers:
Authorization: Bearer <token>
Response (200):
{
"user": {
"id": 1,
"username": "user@example.com"
}
}After authenticating (login or Google), you will receive an access_token. To access protected routes, include this token in the Authorization header:
Authorization: Bearer <access_token>
This project is licensed under the MIT License - see the LICENSE file for details.
Diego Ivan Perea Montealegre
- GitHub: @diegoperea20
Created by Diego Ivan Perea Montealegre