Skip to main content

API Authentication and Authorization System

Build secure API auth and authorization: your chosen auth flow, short-lived JWT access plus refresh rotation, API keys, and role-based access control.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt asks the AI to design a complete authentication and authorization system for your [api_type] API. It implements an [auth_flow] flow, short-lived JWT access tokens ([access_ttl]) with longer refresh tokens ([refresh_ttl]), API-key management for service-to-service auth, role-based access control with [roles], permission-based authorization, token revocation and blacklisting, MFA, OAuth social login via [providers], security headers and CORS, and audit logging — plus a token-storage strategy, CSRF protection, and brute-force prevention.

The structure works because auth is the one area where vague design becomes a security incident. Pinning [auth_flow] (like OAuth 2.0 Authorization Code with PKCE) anchors the entire token lifecycle. The [access_ttl] and [refresh_ttl] split is the core security tradeoff — short access tokens limit the blast radius of a leak while refresh tokens preserve UX. [roles] define the RBAC matrix, and [providers] set up social login. Forcing decisions on token storage and revocation up front prevents the subtle vulnerabilities that surface later.

When to use it

  • You're scoping auth for a new API and refuse to wing the token design
  • You need short-lived access plus refresh-token rotation with [access_ttl] and [refresh_ttl]
  • You're implementing RBAC with [roles] and finer permission checks
  • You need OAuth social login via [providers] alongside your own auth
  • You must decide token storage (httpOnly cookies versus localStorage) deliberately
  • You need token revocation, MFA, and brute-force prevention specified

Example output

Expect a security design: the [auth_flow] sequence, the JWT structure with [access_ttl] and [refresh_ttl] and a refresh-rotation scheme, an API-key model, an RBAC table built from [roles] plus permission checks, a token-revocation/blacklist mechanism, OAuth wiring for [providers], and a storage recommendation with CSRF and brute-force defenses. It reads like a security spec you can hand to reviewers.

Pro tips

  • Keep [access_ttl] short (minutes) so a leaked access token expires fast, and lean on refresh rotation for UX
  • Decide token storage explicitly — httpOnly cookies resist XSS but need CSRF protection; localStorage is simpler but XSS-exposed
  • Map [roles] to real permissions rather than checking roles directly in code; permission checks age better
  • Always pair refresh tokens with rotation and revocation; a long-lived refresh token without revocation is a standing risk
  • For [providers], confirm each one's callback and scope requirements; OAuth details differ per provider
  • Treat audit logging as non-optional; you'll want the auth event trail the first time an account is compromised

Frequently Asked Questions

Why use short-lived access tokens with refresh tokens?
Short-lived access tokens (the `[access_ttl]` default is 15 minutes) limit how long a leaked token is useful, while longer refresh tokens preserve a smooth login experience. This split is the central tradeoff between security and usability in JWT-based auth.
Should I store tokens in cookies or localStorage?
The prompt forces this decision explicitly. httpOnly cookies protect tokens from XSS but require CSRF protection, while localStorage is simpler to implement but exposed to any XSS on your site. The model recommends based on your threat model rather than defaulting blindly.
Does it support social login?
Yes, it wires up OAuth 2.0 social login for the `[providers]` you list, defaulting to Google, GitHub, and Microsoft. Each provider has its own callback URLs and scope requirements, so confirm those details per provider during implementation.
How are tokens revoked before they expire?
It includes token revocation and blacklisting, typically backed by a fast store that checks whether a token has been invalidated. This matters because a stateless JWT is otherwise valid until expiry, so revocation is what lets you log users out or kill compromised sessions immediately.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in API Development Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support