DEV Community

loading...

Keycloak: REST API for new Realm

rounakcodes
Self taught. Full Stack Developer. More than 4 years of experience. Currently working on scaling a SaaS product.
・1 min read

Get access token

  • Code
  curl \
  -d "client_id=admin-cli" \
  -d "username=admin" \
  -d "password=admin" \
  -d "grant_type=password" \
  "http://localhost:8080/auth/realms/master/protocol/openid-connect/token"
Enter fullscreen mode Exit fullscreen mode

Create realm json file

  • Sample
  {
    "id": "newrealm",
    "realm": "newrealm",
    "displayName": "New Realm",
    "enabled": true,
    "sslRequired": "external",
    "registrationAllowed": false,
    "loginWithEmailAllowed": true,
    "duplicateEmailsAllowed": false,
    "resetPasswordAllowed": false,
    "editUsernameAllowed": false,
    "bruteForceProtected": true
  }
Enter fullscreen mode Exit fullscreen mode

Create realm

  • Code
  curl -v POST \
    -H "Authorization: Bearer <access-token>" \
    -H "Content-Type: application/json" \
    -d "@<realm-file>" \ http://localhost:8080/auth/admin/realms
Enter fullscreen mode Exit fullscreen mode

Discussion (0)