Login using AWS
Sign up, sign in and password reset with AWS Cognito, integrated through standard OIDC.
InterfacesAPI SpecSections
API Spec Designed
Base address: https://01scale.com/api/identity/v1. Open an endpoint for its inputs, constraints, errors and samples.
GET/auth/loginStart sign-in or sign-up
Redirects the browser to Cognito's hosted page. This is a link the browser follows, not a call made from code. Public
Inputs
modequerystringoptional- Which Cognito screen opens first.
signinorsignup. Defaultsignin.return_toquerystringoptional- Where to send the user after a successful sign-in.
- A path on 01scale.com: starts with one
/, not//, no scheme or host, at most 512 characters. Default/.
What it does
- Creates
state(32 random bytes),nonce(32 random bytes) and a PKCE code verifier (43 to 128 characters) with its S256 challenge. - Stores them with
modeandreturn_toin the encrypted__Host-01s_logincookie for 10 minutes. - Redirects to Cognito's authorize endpoint with
response_type=code,scope=openid email, the client ID, the callback URL,state,nonceand the code challenge. - If the browser already has a valid session, redirects straight to
return_to.
Responses
- 302Always on success.
Location: the Cognito authorize URL (orreturn_toif already signed in).Set-Cookie:__Host-01s_login. - 422
invalid_modemodeis notsigninorsignup. - 422
invalid_return_toreturn_tois not a same-site path. This blocks open redirects. - 429
rate_limitedMore than 20 requests a minute from one IP address.
Sample request
GET /api/identity/v1/auth/login?mode=signup&return_to=%2Fdocuments HTTP/1.1
Host: 01scale.comSample response
HTTP/1.1 302 Found
Location: https://01scale.auth.us-east-1.amazoncognito.com/oauth2/authorize?response_type=code&client_id=4h8example2k&redirect_uri=https%3A%2F%2F01scale.com%2Fapi%2Fidentity%2Fv1%2Fauth%2Fcallback&scope=openid+email&state=Zk3...&nonce=p9Q...&code_challenge=E9M...&code_challenge_method=S256
Set-Cookie: __Host-01s_login=eyJhbGciOiJkaXIi...; Max-Age=600; Path=/; HttpOnly; Secure; SameSite=LaxGET/auth/callbackFinish sign-in
Cognito sends the browser here after the user signs in. Identity checks the response, creates the user if new, and creates the session. Public
Inputs
codequerystringYes, unlesserroris present- The one-time code from Cognito.
- At most 2,048 characters. Single use, valid a few minutes.
statequerystringrequired- Proves this response belongs to the login this browser started.
- Must equal the
statein the__Host-01s_logincookie, compared in constant time. errorquerystringoptional- The provider's error code.
- Set by Cognito when the user cancels or sign-in fails.
__Host-01s_logincookiestringrequired- The values saved when login started.
- Present, not expired, decrypts correctly.
What it does
- Checks
state, then exchangescodewith Cognito's token endpoint using the client secret and the PKCE code verifier. - Validates the ID token: signature against Cognito's keys, issuer, audience (the client ID), expiry, and
nonce. - Requires
email_verifiedto be true, and an email of at most 254 characters (the longest a mail server accepts). Both are checked before anything is stored. - Finds the user by
cognito_sub. If none exists, creates one and recordsauth.signup. - Revokes that user's sessions created before the token's
auth_timewhen the password was just reset (story IDENTITY-V1-E1-04). - Creates a session, sets
__Host-01s_session, deletes__Host-01s_login, recordsauth.signinand redirects toreturn_to. - Cognito's tokens are used once here and then discarded. They are never stored or sent to the browser.
- On any failure, a browser (a request that accepts
text/html) is redirected to the friendly page/sign-in-error?code=<code>, which explains the problem in plain language with one button to start again. Any other client, such as an app or an AI agent, gets theapplication/problem+jsonerror below. - Every failure is recorded as
auth.signin_failedwith the code as its reason.
Responses
- 302Sign-in succeeded.
Location:return_to.Set-Cookie:__Host-01s_session, and__Host-01s_logincleared. - 302Sign-in failed, and the caller is a browser.
Location:/sign-in-error?code=<code>, with__Host-01s_logincleared. - 400
login_expiredThe login cookie is missing or older than 10 minutes. The user starts again. - 400
login_state_mismatchstatedoes not match, or the ID token'snoncedoes not match. - 400
email_not_verifiedCognito reports the email as unverified. - 422
email_not_supportedThe email is longer than 254 characters, so no user is created. Practically never happens, since Cognito has just sent mail to the address. - 400
provider_errorCognito returnederror(for example the user cancelled), or rejected the code. - 502
provider_unavailableCognito could not be reached. Safe to start again.
Sample request
GET /api/identity/v1/auth/callback?code=4f1c9a7e-example&state=Zk3... HTTP/1.1
Host: 01scale.com
Cookie: __Host-01s_login=eyJhbGciOiJkaXIi...Sample response
HTTP/1.1 302 Found
Location: /documents
Set-Cookie: __Host-01s_session=q3ZxT0m8Jd1sV5nH2bK7wY4cR9uE6aLpF0gI3oXtNzM; Max-Age=604800; Path=/; HttpOnly; Secure; SameSite=Lax
Set-Cookie: __Host-01s_login=; Max-Age=0; Path=/; HttpOnly; Secure; SameSite=LaxGET/sessionWho am I
Returns the signed-in user and when the session ends. Apps call this to decide whether to show Sign in or the user's email. Signed in
Inputs
__Host-01s_sessioncookiestringrequired- The session token. Sent by the browser automatically.
- 43 base64url characters; must match a session that is not revoked and not expired.
What it does
- Read-only. Does not extend the session in version 1.
Responses
- 200A valid session exists. The user, the session's expiry, how they authenticated and their scopes.
- 401
not_authenticatedNo cookie, an unknown token, or a session that is expired or revoked. The same answer in every case. - 429
rate_limitedMore than 120 requests a minute for one session.
Sample request
GET /api/identity/v1/session HTTP/1.1
Host: 01scale.com
Cookie: __Host-01s_session=q3ZxT0m8Jd1sV5nH2bK7wY4cR9uE6aLpF0gI3oXtNzMSample response
{
"user": {
"id": "0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e",
"email": "priya@example.com"
},
"session": {
"id": "0193a5b2-9d40-7c11-a6e3-5f1b2c3d4e5f",
"expires_at": "2026-11-23T09:14:07Z"
},
"auth": "session",
"scopes": [
"*"
]
}POST/auth/logoutSign out
Ends the current session and returns the address that also signs the user out of Cognito. Signed in
Inputs
__Host-01s_sessioncookiestringrequired- The session to end.
- A valid session.
Originheaderstringrequired- Blocks other sites from signing the user out.
- Must be
https://01scale.com(or localhost in development).
What it does
- Sets
revoked_aton the session, clears the cookie and recordsauth.signout. - The client then sends the browser to
logout_url, which clears Cognito's own session so the next sign-in shows the login form. - No request body.
Responses
- 200The session was ended.
logout_url: Cognito's logout address, which returns the user to the home page. - 401
not_authenticatedThere is no valid session to end. - 403
origin_not_allowedTheOriginheader is missing or from another site.
Sample request
POST /api/identity/v1/auth/logout HTTP/1.1
Host: 01scale.com
Origin: https://01scale.com
Cookie: __Host-01s_session=q3ZxT0m8Jd1sV5nH2bK7wY4cR9uE6aLpF0gI3oXtNzMSample response
{
"logout_url": "https://01scale.auth.us-east-1.amazoncognito.com/logout?client_id=4h8example2k&logout_uri=https%3A%2F%2F01scale.com%2F"
}POST/tokenExchange a session for an access token
Called only by the gateway. Turns the session token from the browser's cookie into a 5-minute access token that the other services accept. Service
Inputs
Authorizationheaderstringrequired- Proves the caller is the gateway. Browsers cannot reach this endpoint.
Bearer <gateway service key>. Compared in constant time.session_tokenbodystringrequired- The value of the
__Host-01s_sessioncookie. - Exactly 43 base64url characters.
What it does
- Hashes the token, looks up the session and checks it is not revoked or expired.
- Signs a JWT with the active signing key (algorithm ES256) and the claims listed under Access token.
- The gateway may cache the access token until 30 seconds before it expires.
Responses
- 200The session is valid.
access_token,token_type(alwaysBearer) andexpires_in(always300). - 401
invalid_service_credentialThe gateway key is missing or wrong. - 401
invalid_credentialThe session token is unknown, expired or revoked. - 422
validation_failedsession_tokenis missing or malformed.
Sample request
POST /api/identity/v1/token HTTP/1.1
Authorization: Bearer <gateway service key>
Content-Type: application/json
{
"session_token": "q3ZxT0m8Jd1sV5nH2bK7wY4cR9uE6aLpF0gI3oXtNzM"
}Sample response
{
"access_token": "eyJhbGciOiJFUzI1NiIsImtpZCI6ImsyMDI2LTExIn0.eyJpc3MiOiJodHRwczovLzAxc2NhbGUuY29tL2FwaS9pZGVudGl0eS92MSIsInN1YiI6IjAxOTNhNWIyLi4uIn0.MEUCIQ...",
"token_type": "Bearer",
"expires_in": 300
}GET/jwksPublic keys
The public keys that verify access tokens. Every service fetches this once and caches it. Public
Inputs
None.
What it does
- Returns the active key and any key retired less than 10 minutes ago, so tokens signed just before a rotation still verify.
- Sent with
Cache-Control: public, max-age=300. - Never contains private key material.
Responses
- 200Always. A JSON Web Key Set: one entry per public key.
Sample request
GET /api/identity/v1/jwks HTTP/1.1
Host: 01scale.comSample response
{
"keys": [
{
"kty": "EC",
"crv": "P-256",
"kid": "k2026-11",
"use": "sig",
"alg": "ES256",
"x": "f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU",
"y": "x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"
}
]
}Errors
Every error has the same shape and a stable code to branch on.
{
"type": "https://01scale.com/errors/not_authenticated",
"title": "Not signed in",
"status": 401,
"detail": "Sign in to continue.",
"code": "not_authenticated",
"request_id": "req_0193a61f9c2e"
}Cookies
__Host-01s_login10 minutes- Holds
state,nonce, the PKCE verifier,modeandreturn_towhile the user is at Cognito - Encrypted (JWE). HttpOnly, Secure, SameSite=Lax, Path=/. Deleted on callback.
__Host-01s_session7 days- The session token
- 32 random bytes, base64url (43 characters). HttpOnly, Secure, SameSite=Lax, Path=/. Only its SHA-256 hash is stored.
Access token
A signed token (JWT, ES256) that lives 5 minutes. Browsers never see it.
iss- Who issued the token
- Example:
https://01scale.com/api/identity/v1 sub- The user's ID
- Example:
0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e aud- Who the token is for; services reject any other value
- Example:
01scale iat,exp- Issued at and expiry (5 minutes)
- Example: Unix seconds;
exp=iat+ 300 jti- Unique ID of this token, for logs
- Example: A UUID
sid- The session it came from
- Example:
0193a5b2-9d40-7c11-a6e3-5f1b2c3d4e5f auth- How the caller authenticated: `session` here; `api_key` (Account management), `service` and `delegated` (Service access, `docs/services/identity/v1/service-access`)
- Example:
session scopes- What the caller may do; a browser session has full access to the user's own data
- Example:
["*"] is_admin- Whether admin-only endpoints are allowed
- Example:
false
Handled without an endpoint
- Forgot and reset password (IDENTITY-V1-E1-04)
- Handled entirely on Cognito's hosted page, which answers the same way whether or not the account exists. On the next sign-in, Identity revokes that user's older sessions.
- Route protection (GATEWAY-V1-E1-06)
- Not an Identity endpoint. The gateway redirects signed-out visitors to
/auth/loginwithreturn_toset, returns401for API calls without a session, and each service returns404for another user's data. - Health and contract
- Like every service, Identity also serves
GET /healthandGET /openapi.jsonfrom the service template (SERVICEKIT-V1-E0-05).
Constraints at the API level
modemust besigninorsignup.return_tomust be a path on 01scale.com (starts with one/, not//, at most 512 characters).stateandnoncemust match the values in the login cookie, compared in constant time.- The email from Cognito must be verified and at most 254 characters.
- The login cookie must be present and less than 10 minutes old.
session_tokenmust be exactly 43 base64url characters.POST /auth/logoutmust carry anOriginheader from 01scale.com.POST /tokenmust carry the gateway's service key.- Rate limits at the gateway: 20 a minute per IP on
/auth/loginand/auth/callback; 120 a minute per session on/session. - Every error uses the same shape,
application/problem+json, with a stablecode.