Sign-in flow
My Auths uses the OpenID Connect authorization code flow with PKCE. This page walks through every step with plain HTTP, so you can see what a library does for you. Using a library at the end shows the same flow in a few popular ones.
The examples use https://app.example.com/auth/callback as the redirect URL. Replace it with one registered for your application, and replace CLIENT_ID and CLIENT_SECRET with your application's values.
1. Send the user to My Auths
Create three random values and keep them in the user's session on your server (for example in a short-lived, httpOnly cookie):
state: protects against forged callbacks. You check it in step 2.nonce: comes back inside the ID token, so you know the token was made for this sign-in.code_verifier: a random string of 43 to 128 characters. Its SHA-256 hash, base64url-encoded, is thecode_challenge.
Then redirect the browser to the authorization endpoint:
https://api.myauths.com/oauth2/authorize
?response_type=code
&client_id=CLIENT_ID
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback
&scope=openid%20profile%20email
&state=STATE
&nonce=NONCE
&code_challenge=CODE_CHALLENGE
&code_challenge_method=S256
| Parameter | Required | Value |
|---|---|---|
response_type | Yes | code |
client_id | Yes | Your application's client ID. |
redirect_uri | Yes | One of your registered redirect URLs, character for character. |
scope | Yes | openid, plus profile and email if you need them. |
code_challenge | Yes | The base64url SHA-256 hash of your code_verifier. |
code_challenge_method | Yes | S256. The plain method isn't accepted. |
state | Recommended | Your random state value. |
nonce | Recommended | Your random nonce value. |
What the user sees
The user lands on the My Auths sign-in page, which shows your application's name and logo. From there they can:
- sign in with their email and password, or create an account,
- sign in with Google or GitHub,
- reset a forgotten password.
If they turned on two-step verification, they're asked for a code from their authenticator app next. A user who is already signed in to My Auths skips the form and goes straight back to your app.
The first time your application asks for profile or email, the user sees a consent screen listing what your app wants. Their answer is remembered, so they aren't asked again. A request for openid alone never asks.
2. Handle the callback
My Auths redirects the browser back to your redirect URL:
https://app.example.com/auth/callback?code=AUTHORIZATION_CODE&state=STATE
Check that state is the value you stored before doing anything else. If it doesn't match, stop.
If the sign-in didn't happen, the callback carries an error instead of a code:
error | When |
|---|---|
access_denied | The user declined the consent screen, or isn't allowed to use your application (it's invite-only and they aren't a member, or their membership is suspended). |
invalid_request | A parameter is missing or wrong, for example no PKCE challenge. |
invalid_scope | You asked for a scope other than openid, profile and email. |
If the client_id is unknown or the redirect_uri isn't registered, My Auths answers with an error itself instead of redirecting, because it can't trust the redirect URL.
3. Exchange the code for tokens
From your server, post the code to the token endpoint, authenticating with your client ID and secret using HTTP Basic:
curl -X POST https://api.myauths.com/oauth2/token \
-u "CLIENT_ID:CLIENT_SECRET" \
-d grant_type=authorization_code \
-d code=AUTHORIZATION_CODE \
-d redirect_uri=https://app.example.com/auth/callback \
-d code_verifier=CODE_VERIFIER
{
"access_token": "eyJraWQiOi...",
"refresh_token": "Hk3x9f...",
"id_token": "eyJraWQiOi...",
"token_type": "Bearer",
"expires_in": 299,
"scope": "openid profile email"
}
The code works once and expires after 5 minutes. The redirect_uri must be the same one you sent in step 1.
Before trusting the ID token, check its signature, iss, aud (your client ID), exp, and that its nonce is the one you stored. Tokens and Claims lists what each token contains.
4. Keep the user signed in
Keep the tokens on your server, or in encrypted httpOnly cookies. Don't expose the refresh token to browser JavaScript.
| Token | Lasts | Use it to |
|---|---|---|
| Access token | 5 minutes | Call your API (Authorization: Bearer ...). |
| ID token | 30 minutes | Know who signed in; sign out. |
| Refresh token | 60 minutes, renewed on every refresh | Get new tokens without asking the user to sign in again. |
Refreshing
When the access token is about to expire, refresh:
curl -X POST https://api.myauths.com/oauth2/token \
-u "CLIENT_ID:CLIENT_SECRET" \
-d grant_type=refresh_token \
-d refresh_token=REFRESH_TOKEN
The response has the same shape as in step 3, with a new refresh token. Save it and throw away the old one: every refresh token works only once. The new one lasts another 60 minutes, so a user stays signed in as long as your app refreshes at least once an hour.
A refresh fails with invalid_grant when the refresh token is expired, already used or revoked, or when the user can no longer use your application (suspended, removed from an invite-only app, or their account disabled). Send the user through sign-in again.
5. Sign the user out
Signing out has two parts.
First, from your server, revoke the refresh token so it can't be used again:
curl -X POST https://api.myauths.com/oauth2/revoke \
-u "CLIENT_ID:CLIENT_SECRET" \
-d token=REFRESH_TOKEN \
-d token_type_hint=refresh_token
Then clear your own session and redirect the browser to the end-session endpoint, which ends the user's My Auths session too. Without this step, the next sign-in would go straight through without asking for a password.
https://api.myauths.com/connect/logout
?id_token_hint=ID_TOKEN
&post_logout_redirect_uri=https%3A%2F%2Fapp.example.com%2F
&state=STATE
id_token_hint is the latest ID token you received. post_logout_redirect_uri must be one of the Sign-out redirect URLs on your application's Sign-in tab; My Auths sends the user there afterwards.
Access tokens already issued stay valid until they expire (at most 5 minutes), because APIs verify them without calling My Auths.
Using a library
A certified OpenID Connect library handles PKCE, state, nonce and token checks for you. Configure it with the issuer https://api.myauths.com, and make sure it:
- uses PKCE with
S256, - authenticates to the token endpoint with
client_secret_basic. Some libraries default toclient_secret_post, which My Auths refuses withinvalid_client.
Node.js: openid-client
import * as client from "openid-client";
const config = await client.discovery(
new URL("https://api.myauths.com"),
process.env.MY_AUTH_CLIENT_ID,
undefined,
client.ClientSecretBasic(process.env.MY_AUTH_CLIENT_SECRET),
);
// Sign-in: keep codeVerifier, state and nonce in the user's session.
const codeVerifier = client.randomPKCECodeVerifier();
const state = client.randomState();
const nonce = client.randomNonce();
const signInUrl = client.buildAuthorizationUrl(config, {
redirect_uri: "https://app.example.com/auth/callback",
scope: "openid profile email",
code_challenge: await client.calculatePKCECodeChallenge(codeVerifier),
code_challenge_method: "S256",
state,
nonce,
});
// Callback: pass the full URL the browser came back to.
const tokens = await client.authorizationCodeGrant(config, callbackUrl, {
pkceCodeVerifier: codeVerifier,
expectedState: state,
expectedNonce: nonce,
});
const user = tokens.claims(); // the verified ID token claims
// Later: refresh, and store the new refresh token.
const refreshed = await client.refreshTokenGrant(config, tokens.refresh_token);
Next.js: Auth.js
import NextAuth from "next-auth";
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
{
id: "myauths",
name: "My Auths",
type: "oidc",
issuer: "https://api.myauths.com",
clientId: process.env.MY_AUTH_CLIENT_ID,
clientSecret: process.env.MY_AUTH_CLIENT_SECRET,
authorization: { params: { scope: "openid profile email" } },
checks: ["pkce", "state", "nonce"],
client: { token_endpoint_auth_method: "client_secret_basic" },
},
],
});
Register https://app.example.com/api/auth/callback/myauths as the application's redirect URL. Auth.js doesn't refresh tokens on its own; if your app calls an API with the access token, add a refresh step to its jwt callback.
Spring Boot: Spring Security
spring:
security:
oauth2:
client:
registration:
myauths:
client-id: ${MY_AUTH_CLIENT_ID}
client-secret: ${MY_AUTH_CLIENT_SECRET}
client-authentication-method: client_secret_basic
authorization-grant-type: authorization_code
scope: openid,profile,email
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
provider:
myauths:
issuer-uri: https://api.myauths.com
Turn on PKCE for this confidential client:
@Bean
SecurityFilterChain security(HttpSecurity http, ClientRegistrationRepository clients) throws Exception {
var resolver = new DefaultOAuth2AuthorizationRequestResolver(clients, "/oauth2/authorization");
resolver.setAuthorizationRequestCustomizer(OAuth2AuthorizationRequestCustomizers.withPkce());
http.authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated())
.oauth2Login(login -> login.authorizationEndpoint(endpoint -> endpoint.authorizationRequestResolver(resolver)));
return http.build();
}
Register https://app.example.com/login/oauth2/code/myauths as the application's redirect URL.