kmp-ktor-auth-service

Implements Ktor bearer and JWT authentication services for Kotlin Multiplatform backends.

2|Updated Jun 6, 2026
One-click install
npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-ktor-auth-service-ronjunevaldoz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kmp-ktor-auth-service
Source: https://github.com/ronjunevaldoz/kmp-agent-skills/tree/main/skills/kmp-ktor-auth-service
Command: npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-ktor-auth-service-ronjunevaldoz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Building server-side authentication for Kotlin Multiplatform full-stack apps requires choosing between bearer tokens, JWT, sessions, and Ktor RPC, then wiring login, refresh, logout, and protected routes correctly. This Skill provides a proven Ktor auth service pattern with typed errors, route guards, and a scaffold script so you avoid common mistakes like validating tokens in route handlers or returning 200 on auth failure. ## Core Features & Use Cases - Auth Strategy Guidance: Recommends bearer + JWT as the default, sessions only for stateful browser-style persistence, and Ktor RPC only for Kotlin-to-Kotlin boundaries. - Complete Auth Flows: Covers login, token refresh, logout, and protected routes using Ktor's Authentication plugin with typed AuthResult errors and explicit route guards. - Scaffold Script: Generates a starter auth module (routes, AuthService, TokenService, models, Koin DI module) via scripts/scaffold_auth_service.py. - Use Case: You are building a KMP shopping app backend and need user login with JWT access tokens, refresh token rotation, and guarded order routes — this Skill gives you the install block, service structure, and test patterns with MockEngine. ## Quick Start Ask the agent to scaffold a Ktor auth service with JWT login, refresh, and protected routes for your KMP server module.

Frequently Asked Questions about kmp-ktor-auth-service

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add JWT authentication to a Ktor server?▼

Install Ktor's Authentication plugin with a jwt provider, supplying a verifier and a validate block that checks claims through your AuthService. Guard protected routes by wrapping them in an authenticate("auth-jwt") block rather than validating tokens inside route handlers.

Should I use bearer tokens, sessions, or Ktor RPC for KMP auth?▼

Default to bearer plus JWT for API authorization since it is the most explicit boundary. Use sessions only when you need stateful browser-style persistence, and Ktor RPC only when both client and server are Kotlin-first and procedure-style calls fit better than REST.

How do I test Ktor auth flows without a real server?▼

Use Ktor's MockEngine to build a test HttpClient with scripted responses, and a fake TokenStorage implementation for state assertions. This lets you verify login success, 401 error mapping, and refresh-token clearing without network calls.

Why are my JWT tokens being rejected by Ktor?▼

Token rejection usually comes from inconsistency between the verifier and validate blocks in the JWT install configuration. Check that the verifier signs with the same algorithm and secret used at issuance, and that claim validation matches the issued token structure.

When should I not use Ktor RPC for authentication?▼

Avoid Ktor RPC for public APIs with non-Kotlin consumers, simple REST resources, or auth flows needing explicit HTTP semantics. It fits internal Kotlin-to-Kotlin service calls where strongly typed request and response pairs are the priority.