-
Notifications
You must be signed in to change notification settings - Fork 0
Guide Authentication
GitHub Actions edited this page Jan 25, 2026
·
2 revisions
Lerne, wie du Authentication und Authorization in VelinScript implementierst.
@POST("/api/auth/login")
fn login(email: string, password: string): JWTToken {
// Prüfe Credentials
let user = db.findByEmail(User, email);
if (user == null || !verifyPassword(password, user.password)) {
return HttpResponse::unauthorized("Invalid credentials");
}
// Generiere Token
let auth: AuthService = AuthService.new("secret-key");
let claims = UserClaims {
user_id: user.id,
email: user.email,
roles: user.roles,
};
return auth.generateToken(claims);
}
@Auth
@GET("/api/profile")
fn getProfile(token: string): User {
let auth: AuthService = AuthService.new("secret-key");
let claims = auth.verifyToken(token);
if (claims == null) {
return HttpResponse::unauthorized("Invalid token");
}
return db.find(User, claims.user_id);
}
Die @Role Annotation nutzt nun echte JWT-Claims. Der Token muss ein roles Array im Payload enthalten.
@Auth
@Role("admin")
@GET("/api/admin/users")
fn getAdminUsers(): List<User> {
return db.findAll(User);
}
@Auth
@Role("user")
@GET("/api/users/:id")
fn getUser(id: string): User {
return db.find(User, id);
}
VelinScript unterstützt nun nativ TOTP (Time-based One-Time Passwords).
@POST("/api/auth/mfa/verify")
fn verifyMfa(userId: string, code: string): boolean {
let user = db.find(User, userId);
// Verifiziert den Code gegen das gespeicherte Secret
// Nutzt im Hintergrund das 'totp-rs' Crate für RFC 6238 Konformität
return MFAService.verify_totp(code, user.mfaSecret);
}
@GET("/api/auth/oauth/authorize")
fn oauthAuthorize(provider: string): string {
let oauth = OAuth2Provider::new(
getClientId(provider),
getClientSecret(provider),
getRedirectUri(provider)
);
let state = generateState();
let auth_url = oauth.get_authorization_url(state);
return auth_url;
}
@GET("/api/auth/oauth/callback")
fn oauthCallback(code: string, state: string): JWTToken {
let oauth = OAuth2Provider::new(
getClientId("oauth"),
getClientSecret("oauth"),
getRedirectUri("oauth")
);
let token = oauth.exchange_code(code);
return token;
}
- Sichere Secrets verwenden
- Token Expiry implementieren
- HTTPS für alle Auth-Endpoints
- Rate Limiting für Login-Endpoints
- Tutorial 7: ML Integration - KI/ML Features
- Compiler Architecture
- Pass-Verlauf
- Type Inference
- Code Ordering
- IR Representation
- Borrow Checker
- Code Generation
- Multi-Target Compilation
- Module Resolution
- Framework Integration
- Parallelization
- AI Compiler Passes
- Prompt Optimizer
- System Generation
- Basics
- APIs
- Security
- Database
- Validation
- Authentication
- ML/LLM
- Intelligence Features
- Type Inference
- ML Training
- Pattern Matching
- Closures
- Collections
- HTTP Client
- String Interpolation
- Debugger
- Vektor-Datenbanken
- CLI Reference
- API Keys Setup
- Advanced
- Backend
- Security Best Practices
- AI/ML
- Auto Imports
- Plugin Development