This project is a backend API service for a learning portal, built on ASP.NET Core Web API, using SQL Server and Entity Framework Core, with JWT and Google authentication.
- .NET 6+ SDK
- SQL Server (local or remote)
- (Optional but recommended) VS Code or Visual Studio for C#
- Clone the repository
git clone https://bitbucket.org/dotnetreact/.netreacttraining2025/src/master/
cd AuthCheck
- Configure Environment Variables
Create (or update) appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=YOUR_SQL_SERVER;Database=LearningPortalDB;User Id=YOUR_USER;Password=YOUR_PASSWORD;TrustServerCertificate=True;"
},
"Jwt": {
"Key": "YOUR_JWT_SECRET_KEY",
"Issuer": "LearningPortal",
"Audience": "LearningPortalUsers"
},
"Google": {
"ClientId": "your-google-client-id.apps.googleusercontent.com"
},
"AllowedHosts": "*"
}
- Edit connection string for your SQL Server.
- Set your JWT key (used to sign tokens).
- Google ClientId: For Google login.
- Apply Entity Framework Migrations
dotnet ef database update
If you have not added migrations yet:
dotnet ef migrations add InitialCreate
dotnet ef database update
Simply run:
dotnet run
API will be available at:
http://localhost:5000 (default port, see launchSettings.json)
/Controllers— API endpoints (users, courses, assignments, auth, etc.)/Entities— EF Core models/Data— DbContext and data seeders/Services— Business logic/services/Enums— Enum definitions (progress, status, etc.)/Model— DTOs and request/response objectsProgram.cs— Startup/configuration logic (or justProgram.csfor minimal hosting)
-
JWT Authentication:
- Tokens are generated and required on all protected endpoints.
- Set
Jwt:Keyin your config and keep it secret! - Pass token in the
Authorization: Bearer <token>header.
-
Google Login:
- Specify your Google ClientId in
appsettings.json. - Frontend posts Google id_token to
/api/Auth/googleAuth.
- Specify your Google ClientId in
- Swagger UI: Automatic API docs at
/swaggerwhen running locally. - Entity Framework Core: For migrations and DB schema.
- CORS: Configurable in
Startup.csorProgram.cs.
Ensure React frontend origin (e.g.,http://localhost:3000) is added as an allowed origin.
- Login:
POST /api/Auth/login - Register:
POST /api/Auth/register - Google Auth:
POST /api/Auth/googleAuth - Current user:
GET /api/account/me - Courses, assignments, submissions, progress: RESTful routes under
/api/
See Swagger UI for interactive docs.
- SQL connection errors: Check your connection string, user/password, and SQL Server status.
- JWT issues: Make sure your
Jwt:Keymatches and token is passed as a Bearer header. - CORS: Adjust allowed origins in your config.
- Google login issues: Double check the ClientId and Google Console settings.
- Check logs for errors and exceptions; default logging to console in dev mode.
- You can seed the database through
DataSeed.csor your own scripts.
MIT (Or your license here)