惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
IT之家
IT之家
Google DeepMind News
Google DeepMind News
罗磊的独立博客
爱范儿
爱范儿
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
U
Unit 42
MongoDB | Blog
MongoDB | Blog
S
SegmentFault 最新的问题
B
Blog
博客园 - 叶小钗
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Structure Authentication in .NET (JWT + Refresh Tok...
Ayman Atif · 2026-05-01 · via DEV Community
If you’ve built a few .NET APIs, you’ve probably done authentication more than once. JWT setup login and register endpoints protecting routes maybe adding roles It works, but every time I started a new project, I found myself repeating the same setup again. After doing this a few times, I decided to settle on a structure that I can reuse and understand without digging through tutorials. This is the approach I use now. The goal I’m not trying to build a full identity system. I just want: a clean login and register flow JWT authentication that works refresh tokens so users don’t get logged out constantly a structure that doesn’t turn into a mess later The structure I keep things split into simple layers. Api Application Domain Infrastructure Shared Nothing fancy. Just enough separation so things don’t get mixed together. The API handles HTTP and controllers. The Application layer contains the logic like login and register. The Domain has the core models like User and Role. Infrastructure deals with the database and token generation. Shared contains helpers like password hashing. This makes it easy to change one part without breaking everything. Authentication flow Here’s how the flow works. 1. Register or login User sends email and password. Password is hashed before storing it. If login is successful, the API returns: a JWT access token a refresh token 2. Access protected endpoints The client sends: Authorization: Bearer The API validates: signature issuer audience expiration If everything checks out, the request goes through. 3. Refresh token When the access token expires, the client sends the refresh token. If it is valid: a new access token is generated a new refresh token replaces the old one This avoids forcing users to log in again. 4. Roles Each user has a role like User or Admin. Then I can protect routes like this: [ Authorize ] [ HttpGet ( "protected" )] public IActionResult Protected () { ... } [ Authorize ( Roles = "Admin" )] [ HttpGet ( "admin-only" )] public IActionResult AdminOnly () { ... } Simple and clear. Why I use refresh tokens JWT alone is not enough for real apps. If the token expires quickly, users get logged out often. If it lasts too long, it becomes a security risk. Refresh tokens solve that. Short lived access token longer lived refresh token You keep security and still have a smooth experience. Database choice For this kind of starter, I use SQLite. No setup needed works out of the box easy to switch later The database file is created on first run, which makes testing simple. What I keep simple on purpose I don’t try to solve everything here. No email verification No password reset No advanced permissions Those can be added later depending on the project. This is just a clean starting point. Try it yourself I put a free demo here: https://github.com/i95compile/.Net-Auth-System-Core-Demo.git You can run it, test the endpoints, and see how everything is structured. If you want the full version I also packaged a version you can reuse directly in your projects. Same structure, ready to plug in and extend. If you’re tired of rebuilding auth every time, this can save you a bit of time. yaman95.gumroad.com Final thought Authentication is one of those things that is not hard, but it’s easy to waste time on. Having a clean base you understand makes a big difference when starting new projects. That’s what I aimed for here.