Skip to content

samer-k/Lab

Repository files navigation

SMHI MetObs API

Build .NET C# License Auth0

ASP.NET Core Web API that combines SMHI meteorological observations with Auth0 authentication.

Features

  • Merged weather data - Combines air temperature and gust wind observations from SMHI
  • Auth0 authentication - Secure API access with JWT bearer tokens
  • Google sign-in - OAuth 2.0 flow via Auth0 Universal Login
  • Station discovery - Browse available SMHI weather stations
  • Swagger UI - Interactive API documentation with built-in authentication
  • Rate limiting - Protects against abuse
  • Caching - Reduces load on SMHI's public API

Quick Start

Prerequisites

1. Clone and Restore

git clone https://github.com/samer-k/Lab.git
cd Lab
dotnet restore SmhiMetobs.slnx

2. Configure Auth0

See detailed Auth0 setup guide.

Quick version:

# Create Auth0 applications
auth0 apps create -n "SMHI MetObs" -t regular \
  -c https://localhost:7195/auth/callback

# Store credentials in user-secrets
dotnet user-secrets set --project src/SmhiMetobs.Api \
  "Auth0:Domain" "your-tenant.auth0.com"
dotnet user-secrets set --project src/SmhiMetobs.Api \
  "Auth0:ClientId" "your-client-id"
# ... (see full guide for remaining secrets)

3. Run

dotnet run --project src/SmhiMetobs.Api --launch-profile https

Open Swagger UI: https://localhost:7195/swagger

API Endpoints

Get Observations

GET /api/observations
GET /api/observations?stationId=97280&period=latest-hour

Authentication: Required (Bearer token)
Response: Merged Lufttemperatur and Byvind observations

Get Access Token

GET /auth/access-token

Authentication: None
Usage: Browser-only, initiates OAuth flow

Get Stations

GET /api/stations

Authentication: None
Response: List of available SMHI stations

Documentation

Testing

Run unit tests (fast, no external dependencies):

dotnet test --filter "Category!=RequiresAuth0"

Run all tests (requires Auth0 setup):

dotnet test

See Testing Guide for details on test categories and why integration tests are excluded from CI/CD.

Project Structure

Lab/
├── src/
│   └── SmhiMetobs.Api/          # Main API project
│       ├── Endpoints/           # Minimal API endpoints
│       ├── Services/            # Business logic
│       ├── Models/              # DTOs and SMHI data models
│       ├── Authentication/      # Auth schemes and policies
│       └── README.md           # Implementation details
├── tests/
│   └── SmhiMetobs.Api.Tests/   # Test suite
│       └── README.md           # Testing guide
└── README.md                   # This file

Technology Stack

  • .NET 10 - Latest .NET framework
  • ASP.NET Core Minimal APIs - Lightweight endpoint handlers
  • Auth0 - Authentication and authorization
  • Swashbuckle - OpenAPI/Swagger documentation
  • xUnit - Testing framework

License

MIT License

Contributing

This is a personal learning project. Feel free to fork and experiment!

Resources

About

ASP.NET Core Web API for SMHI weather observations with Auth0 authentication

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages