Skip to content

Authentication Providers

The package supports modular authentication configuration, allowing you to switch between providers with a single option.

Available Providers

ProviderDescriptionUse Case
guestSimple guest authenticationDevelopment, simple tests
keycloakOIDC via KeycloakProduction-like auth testing
githubOAuth via GitHubTesting where github authentication is needed

Guest Authentication

Guest authentication allows users to enter without credentials, using a simple "Enter as Guest" button.

Configuration

typescript
await rhdh.configure({ auth: "guest" });
await rhdh.deploy();

Usage in Tests

typescript
test.beforeEach(async ({ loginHelper }) => {
  await loginHelper.loginAsGuest();
});

When to Use Guest Auth

  • Quick development testing
  • Tests that don't require user identity
  • Simplified CI/CD pipelines
  • Tests focused on UI behavior, not auth

Skipping Keycloak Deployment

When using guest auth, skip Keycloak deployment:

bash
SKIP_KEYCLOAK_DEPLOYMENT=true yarn playwright test

Keycloak Authentication

Keycloak provides OIDC authentication for realistic auth testing.

Configuration

typescript
await rhdh.configure({ auth: "keycloak" });
await rhdh.deploy();

Prerequisites

Keycloak must be deployed and configured. This happens automatically via global setup unless skipped.

Usage in Tests

typescript
test.beforeEach(async ({ loginHelper }) => {
  // Use default test user (test1/test1@123)
  await loginHelper.loginAsKeycloakUser();

  // Or specify credentials
  await loginHelper.loginAsKeycloakUser("test1", "test1@123");
});

Default Keycloak Users

UsernamePasswordDescription
test1test1@123Default test user with standard permissions
test2test2@123Secondary test user for multi-user scenarios

Environment Variables

You can override these defaults using environment variables:

  • KEYCLOAK_USERNAME - Override the default username
  • KEYCLOAK_PASSWORD - Override the default password

For more details, see Keycloak Deployment.

Creating Custom Users

typescript
import { KeycloakHelper } from "@red-hat-developer-hub/e2e-test-utils/keycloak";

test.beforeAll(async ({ rhdh }) => {
  const keycloak = new KeycloakHelper();

  // Connect to existing Keycloak
  await keycloak.connect({
    baseUrl: process.env.KEYCLOAK_BASE_URL!,
    username: "admin",
    password: "admin123",
  });

  // Create custom users
  await keycloak.createUser("rhdh", {
    username: "admin-user",
    password: "adminpass",
    groups: ["admins"],
  });

  await keycloak.createUser("rhdh", {
    username: "viewer-user",
    password: "viewerpass",
    groups: ["viewers"],
  });

  await rhdh.configure({ auth: "keycloak" });
  await rhdh.deploy();
});

When to Use Keycloak Auth

  • Testing role-based access control
  • Testing user-specific features
  • Production-like testing scenarios
  • Testing logout/session flows

GitHub Authentication

Allows authentication using github OAuth application.

Configuration

typescript
await rhdh.configure({ auth: "github" });
await rhdh.deploy();

Logging in to GitHub

GitHub login is available via LoginHelper:

typescript
test.beforeEach(async ({ loginHelper }) => {
  await loginHelper.loginAsGithubUser();
});

By default, test user credentials will be pulled from the global workspace in vault.

WARNING

GitHub authentication requires 2FA secret for automated logins. This is more complex to set up than guest or Keycloak auth.

Environment Variables

Guest Auth

No additional environment variables required.

Keycloak Auth

These are automatically set by KeycloakHelper.configureForRHDH() or populated from global workspace in the vault:

VariableDescription
KEYCLOAK_BASE_URLKeycloak instance URL
KEYCLOAK_REALMRealm name
KEYCLOAK_CLIENT_IDOIDC client ID
KEYCLOAK_CLIENT_SECRETOIDC client secret
KEYCLOAK_METADATA_URLOIDC discovery URL
KEYCLOAK_LOGIN_REALMLogin realm name
VAULT_KEYCLOAK_ADMIN_USERNAMEAdmin username
VAULT_KEYCLOAK_ADMIN_PASSWORDAdmin password

GitHub Auth

Configuring github auth provider will populate the following variables from global workspace in the vault:

VariableDescription
VAULT_GITHUB_OAUTH_OVERLAYS_APP_IDGitHub OAuth application ID
VAULT_GITHUB_OAUTH_OVERLAYS_APP_SECRETGitHub OAuth application client secret
VAULT_GH_USER_IDGitHub test user
VAULT_GH_USER_PASSPassword for GitHub test user
VAULT_GH_2FA_SECRETTwo-factor auth secret for GitHub test user
VAULT_GITHUB_USER_TOKENToken for GitHub test user

Configuration Merging

When you set auth: "guest", auth: "keycloak", or auth: "github", the package automatically includes auth-specific configurations:

Package configs:
├── common/                    # Always applied
│   ├── app-config-rhdh.yaml
│   ├── dynamic-plugins.yaml
│   └── rhdh-secrets.yaml
└── auth/
    ├── guest/                 # Applied when auth: "guest"
    │   └── app-config.yaml
    └── keycloak/              # Applied when auth: "keycloak"
    │   ├── app-config.yaml
    │   ├── dynamic-plugins.yaml
    │   └── secrets.yaml
    └── github/                # Applied when auth: "github"
        ├── app-config.yaml
        └── secrets.yaml

Your project configs are merged on top, so you only need to override what's different.

Switching Auth Providers

In Different Test Files

typescript
// guest-tests.spec.ts
test.beforeAll(async ({ rhdh }) => {
  await rhdh.configure({ auth: "guest" });
  await rhdh.deploy();
});

// keycloak-tests.spec.ts
test.beforeAll(async ({ rhdh }) => {
  await rhdh.configure({ auth: "keycloak" });
  await rhdh.deploy();
});

// github-tests.spec.ts
test.beforeAll(async ({ rhdh }) => {
  await rhdh.configure({ auth: "github" });
  await rhdh.deploy();
});

In Different Projects

typescript
// playwright.config.ts
export default defineConfig({
  projects: [
    {
      name: "guest-tests",
      testMatch: "**/guest-*.spec.ts",
    },
    {
      name: "keycloak-tests",
      testMatch: "**/keycloak-*.spec.ts",
    },
    {
      name: "github-tests",
      testMatch: "**/github-*.spec.ts",
    },
  ],
});

Each project gets its own namespace and deployment with different auth.

Best Practices

  1. Use guest auth for speed - Faster to set up and run
  2. Use Keycloak for RBAC testing - When you need user roles
  3. Use GitHub for tests that connect to Github - When you need authentication to GitHub
  4. Create test users per test suite - Avoid shared state
  5. Clean up custom users - Remove users created during tests
  6. Use environment variables - Don't hardcode credentials

Released under the Apache-2.0 License.