/saaskit:implement-saaskitfrom saaskit
Implements SaaSKit login so an agent can add a login route, a callback, session cookies, and logout. Use when the user wants to add SaaSKit login, a callback, or logout. It does not store, validate, refresh, or revoke a session after login (that's `manage-saaskit-sessions`) or write Next.js App Router auth (that's `implement-saaskit-nextjs`) or write Django, FastAPI, or Flask auth (that's `implement-saaskit-python`).
Ships in saaskit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Add login, callback, session cookies, and logout. Then stop.
redirectUri identical to the dashboard Allowed callback URL.manage-saaskit-sessions instead.setup-saaskit already wrote env and registered the redirect. Start there.SCALEKIT_ENVIRONMENT_URL, SCALEKIT_CLIENT_ID, SCALEKIT_CLIENT_SECRET, and SCALEKIT_REDIRECT_URI. Never SCALEKIT_ENV_URL.setup-saaskit already printed a Node login URL.implement-saaskit-nextjs and stop.implement-saaskit-python and stop.cookieParser() before the auth routes. Logout reads req.cookies.idToken.HttpOnly, Secure in production, sameSite: 'lax'. strict breaks the OAuth callback./api and refresh to /auth/refresh if you set both./dashboard does not receive the access cookie. Protect /api/* only. The page calls /api.getLogoutUrl takes one object: { idTokenHint, postLogoutRedirectUri }. The URL is one-time.implement-saaskit-nextjs. Stop.implement-saaskit-python. Stop.If env is missing, collect the four values from app.scalekit.com → Developers → Settings → API Credentials. Register SCALEKIT_REDIRECT_URI under Authentication → Redirect URLs → Allowed callback URLs. Do not invent values.
Done when: this skill is the right path, and the four env names exist.
Install @scalekit-sdk/node only when the repo has no Scalekit SDK yet. Install cookie-parser if Express has no cookie parser yet.
import { ScalekitClient } from '@scalekit-sdk/node';
import cookieParser from 'cookie-parser';
import { randomBytes } from 'node:crypto';
const scalekit = new ScalekitClient(
process.env.SCALEKIT_ENVIRONMENT_URL,
process.env.SCALEKIT_CLIENT_ID,
process.env.SCALEKIT_CLIENT_SECRET
);
const redirectUri = process.env.SCALEKIT_REDIRECT_URI;
app.use(cookieParser());
Done when: the client initializes from those env vars.
Generate a random state per login and keep it in a short-lived HttpOnly cookie. The callback checks it (CSRF).
app.get('/auth/login', (req, res) => {
const state = randomBytes(32).toString('hex');
res.cookie('oauthState', state, {
maxAge: 10 * 60 * 1000,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/auth/callback',
});
const authorizationUrl = scalekit.getAuthorizationUrl(redirectUri, {
scopes: ['openid', 'profile', 'email', 'offline_access'],
state,
});
res.redirect(authorizationUrl);
});
Done when: /auth/login sets the oauthState cookie and redirects to that URL with the same state.
Use the same redirectUri as Step 3. Check state and error before the code exchange. Then redirect off /auth/callback.
app.get('/auth/callback', async (req, res) => {
const { code, error, error_description, state } = req.query;
const storedState = req.cookies.oauthState;
res.clearCookie('oauthState', { path: '/auth/callback' });
if (!state || state !== storedState) {
return res.redirect('/login?error=invalid_state');
}
if (error) {
console.error('Authentication error:', error, error_description);
return res.redirect('/login?error=auth_failed');
}
if (!code) {
return res.redirect('/login?error=missing_code');
}
const { idToken, accessToken, refreshToken, expiresIn } =
await scalekit.authenticateWithCode(code, redirectUri);
res.cookie('accessToken', accessToken, {
maxAge: (expiresIn - 60) * 1000,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/api',
});
res.cookie('refreshToken', refreshToken, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/auth/refresh',
});
res.cookie('idToken', idToken, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
path: '/',
});
res.redirect('/dashboard');
});
| Token | Purpose |
|---|---|
idToken | User profile. Keep it for logout. |
accessToken | Short-lived. Roles and permissions. |
refreshToken | Long-lived. Used later to renew access. |
Do not validate or refresh here. That is manage-saaskit-sessions.
Done when: the callback rejects a missing or mismatched state and an error param, exchanges code, sets the three cookies, and the browser leaves /auth/callback.
Clear the cookies from Step 4, then redirect to Scalekit. The logout URL is one-time.
app.get('/auth/logout', (req, res) => {
const idTokenHint = req.cookies.idToken;
res.clearCookie('accessToken', { path: '/api' });
res.clearCookie('refreshToken', { path: '/auth/refresh' });
res.clearCookie('idToken', { path: '/' });
const postLogoutRedirectUri = `${req.protocol}://${req.get('host')}`;
const logoutUrl = scalekit.getLogoutUrl({
idTokenHint,
postLogoutRedirectUri,
});
res.redirect(logoutUrl);
});
Register that same origin as a Post logout URL. Local default is http://localhost:3000.
Done when: cookies are gone and the browser hits the logout URL.
Name manage-saaskit-sessions for store, validate, refresh, and revoke.
Done when: manage-saaskit-sessions is named, and this skill has stopped.
setup-saaskit if env or the redirect URI is missingmanage-saaskit-sessions to store, validate, refresh, or revokeimplement-saaskit-nextjs for Next.js App Routerimplement-saaskit-python for Django, FastAPI, or FlaskWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub scalekit-inc/authstack --plugin saaskit15 skills in this plugin
/add-api-authAdds API key or client-credentials auth so an agent can protect an API. Use when the user wants an API key or client credentials. It does not put OAuth 2.1 on an MCP server (that's `add-mcp-oauth`) or write SaaSKit login (that's `implement-saaskit`).
/add-mcp-oauthAdds MCP OAuth so an agent can protect the user's MCP server. Use when the user wants MCP OAuth or to protect their MCP server. It does not add API keys or client credentials (that's `add-api-auth`) or expose AgentKit tools over MCP (that's `expose-agentkit-mcp`).
/check-saaskit-prodChecks SaaSKit production so an agent can finish a go-live checklist. Use when the user wants SaaSKit production or to go live SaaSKit. It does not write login (that's `implement-saaskit`) or run dryrun (that's `run-dryrun`).
Other plugins' skills for the same job