Skip to main content

Single sign-on

Let people sign in to the web UI and call the API with your OpenID Connect provider.

Prerequisites​

  • An OpenID Connect provider you administer: Keycloak, Microsoft Entra ID, Okta or Google.
  • A running afe serve with AFE_API_TOKEN set.
  • The address people use to reach the server, for example https://afe.my-company.test.

Steps​

  1. Register a client in your provider.

    • Type: confidential client, authorization code flow with PKCE.
    • Redirect URI: https://afe.my-company.test/auth/oidc/callback.
    • Copy the issuer URL, the client id and the client secret.
  2. Make the provider send a groups claim in the token. Skip this step if nobody needs the administrator role.

  3. Set the variables before you start serve:

    export AFE_OIDC_ISSUER=https://keycloak.example.com/realms/afe
    export AFE_OIDC_CLIENT_ID=afe
    export AFE_OIDC_CLIENT_SECRET=... # never commit this value
    export AFE_OIDC_ADMIN_GROUPS=afe-admins # comma-separated
    afe serve
  4. Open /login. The page now shows a single sign-on button next to the token field.

  5. Call the API with the provider's access token:

    Authorization: Bearer <access token>

    The server checks the signature, the issuer, the audience and the expiry. It never keeps the provider's token.

  6. Let people sign in from a terminal. Register a second client in the provider. Make it public, with no secret, and turn on the OAuth device authorization grant. Then set its id before you start serve:

    export AFE_OIDC_CLI_CLIENT_ID=afe-cli

    afe login reads the issuer and this client id from GET /auth/cli. The server accepts the tokens of both clients. See afe login.

The bootstrap token keeps working as the administrator local. People who sign in are not administrators unless one of their groups is in AFE_OIDC_ADMIN_GROUPS.

On Kubernetes, set spec.deployment.api.oidc of the AgentFlowEngine instead. The operator passes the variables to serve and reads the client secret from a Secret you name. See Identity and audit.

Provider notes​

Keycloak. The issuer is https://<host>/realms/<realm>. Add a Group Membership mapper to the client, with the claim name groups and Full group path off.

Microsoft Entra ID. The issuer is https://login.microsoftonline.com/<tenant>/v2.0. Entra issues access tokens whose audience is api://<id>, not the client id. Set AFE_OIDC_AUDIENCE=api://<id>. Group claims carry object ids, so put those ids in AFE_OIDC_ADMIN_GROUPS.

Okta. The issuer is your authorization server, for example https://<org>.okta.com/oauth2/default. Add a groups claim to the ID token and the access token. The default access token audience is api://default: set AFE_OIDC_AUDIENCE to it.

Google. The issuer is https://accounts.google.com. Google sends no groups claim, so nobody gets the administrator role through single sign-on. Use the bootstrap token or a service account for administration.

SAML. The engine speaks OpenID Connect only. Put a broker in front of your SAML provider: Keycloak can sign people in with SAML and expose them to afe as an OpenID Connect client. Then follow the Keycloak notes.

Troubleshooting​

The button does not appear. AFE_OIDC_ISSUER or AFE_OIDC_CLIENT_ID is unset, or the server cannot be reached by the browser at the registered address.

The browser returns to /login?error=sso. The redirect URI is not registered, the client secret is wrong, or the ID token failed a check. The page never shows the provider's message. Read your provider's log.

afe login says single sign-on is off. GET /auth/cli answers 404. AFE_OIDC_ISSUER or AFE_OIDC_CLI_CLIENT_ID is unset.

The API answers 401 to a valid token. The token audience differs from the one the server expects. Set AFE_OIDC_AUDIENCE to the aud value of the token. It defaults to the client id.

A person is not an administrator. The group is missing from the token, or the claim has another name. Set AFE_OIDC_GROUPS_CLAIM.

See also​