Keycloak
Connect your Keycloak server to Squid to authorize user actions like querying and updating data, calling executables, and more.
Keycloak is an open-source identity and access management solution that provides single sign-on, user federation, and fine-grained authorization.
To use the Keycloak connector with Squid, first connect your Keycloak server to Squid using the following steps:
- Navigate to the Squid Console. Choose your app and environment (dev or prod), and then click the Integrations tab.
- Provide the following details:
- Integration ID - Choose an ID that is brief and helps identify the integration.
- Domain - Your Keycloak server URL (e.g.,
https://keycloak.example.com). - Realm - The name of your Keycloak realm.
- Client ID - Your OAuth 2.0 client ID configured in the Keycloak realm.
- Click Add integration.

Token requirements
Squid validates each token's issuer and audience, so two things must line up:
- Issuer: the token's
issclaim must equal<Domain>/realms/<Realm>. Set Domain to the issuer URL Keycloak advertises to clients; an internal hostname that only serves JWKS does not work. - Audience: the token's
audclaim must contain the Client ID. Keycloak access tokens often omit the client fromaudby default, so add an Audience mapper to the client (Client scopes, then the client's dedicated scope, then Add mapper of type Audience, with the included client audience set to the client and Add to access token on).
A token that fails either check is treated as unauthenticated rather than hard-rejected: the request proceeds without a user, so it fails wherever a security rule requires one, while public paths still run. Clients should refresh tokens shortly before they expire: Squid allows only a 60 second clock skew on token timestamps.
Using the connector
Once you've created a connector, you can use the Squid Client SDK to pass the Keycloak token to Squid:
import Keycloak from 'keycloak-js';
const keycloak = new Keycloak({
url: 'https://keycloak.example.com',
realm: 'your-realm',
clientId: 'your-client-id',
});
// Initialize Keycloak before setting the auth provider
await keycloak.init({ onLoad: 'login-required' });
squid.setAuthProvider({
integrationId: 'KEYCLOAK_INTEGRATION_ID',
getToken: () => keycloak.token,
});
Once the token is passed to the client, Squid will automatically populate the user's authentication information for use in your backend functions:
@secureCollection('users', 'read')
secureUsersRead(context: QueryContext<User>): boolean {
const userAuth = this.getUserAuth();
}