{"id":21877621,"url":"https://github.com/rbiedrawa/spring-webflux-keycloak-demo","last_synced_at":"2025-10-19T09:37:09.833Z","repository":{"id":162193132,"uuid":"355306608","full_name":"rbiedrawa/spring-webflux-keycloak-demo","owner":"rbiedrawa","description":"This repository demonstrates how to use reactive Spring Security with OAuth2 and Keycloak. Keycloak server with all components can be started using docker-compose and utility script.","archived":false,"fork":false,"pushed_at":"2022-01-31T02:10:28.000Z","size":269,"stargazers_count":27,"open_issues_count":0,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T02:44:08.432Z","etag":null,"topics":["docker","docker-compose","jwt","jwt-authentication","keycloak","oauth2","postman","postman-collection","reactor","security","spring-boot","spring-security","spring-security-5","spring-security-oauth2","spring-webflux","testing","webflux-security","wiremock"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rbiedrawa.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-04-06T19:26:46.000Z","updated_at":"2025-01-19T01:06:17.000Z","dependencies_parsed_at":"2023-12-07T20:45:11.180Z","dependency_job_id":null,"html_url":"https://github.com/rbiedrawa/spring-webflux-keycloak-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rbiedrawa/spring-webflux-keycloak-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbiedrawa%2Fspring-webflux-keycloak-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbiedrawa%2Fspring-webflux-keycloak-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbiedrawa%2Fspring-webflux-keycloak-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbiedrawa%2Fspring-webflux-keycloak-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbiedrawa","download_url":"https://codeload.github.com/rbiedrawa/spring-webflux-keycloak-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbiedrawa%2Fspring-webflux-keycloak-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267293817,"owners_count":24065326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","jwt","jwt-authentication","keycloak","oauth2","postman","postman-collection","reactor","security","spring-boot","spring-security","spring-security-5","spring-security-oauth2","spring-webflux","testing","webflux-security","wiremock"],"created_at":"2024-11-28T08:09:47.610Z","updated_at":"2025-10-19T09:37:09.782Z","avatar_url":"https://github.com/rbiedrawa.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reactive Spring Security with OAuth2 and Keycloak (demo)\n\nThis repository demonstrates how to use reactive Spring Security with OAuth2 and Keycloak.\n\nKeycloak server with all components can be started using [docker-compose](./docker/docker-compose.yml) and [utility script](./docker/setupDemoRealm.sh).\n\n## Features\n\n* OAuth2 resource server.\n* Keycloak integration.\n* Reactive method security.\n* Reactive test support.\n* Wiremock integration.  \n* Automated script for creation of `demo` realm.\n* Postman collection with Oauth2 setup.\n\n## Getting Started\n\n### Prerequisites\n\n* Java 11\n* Docker\n* Docker Compose\n\n### Usage\n\n* Start docker compose (keycloak and postgres)\n  ```shell\n  cd docker\n  \n  docker-compose up -d\n  ```\n  \n* Check if all services started.\n  ```shell\n  docker-compose ps   \n\n  # Name                     Command               State                Ports\n  # ---------------------------------------------------------------------------------------------\n  # docker_keycloak_1   /opt/jboss/tools/docker-en ...   Up      0.0.0.0:8081-\u003e8080/tcp, 8443/tcp\n  # docker_postgres_1   docker-entrypoint.sh postgres    Up      5432/tcp\n  ```\n  \n* Open your web browser and go to Keycloak [login page](http://localhost:8081/). On the login page, enter `admin` for a username and password.\n\n* Start creation script for `demo` realm.\n  ```shell\n  sh setupDemoRealm.sh\n  \n  # Starting creation of demo realm. Your clientId: spring_keycloak_demo_client clientSecret: 9ee1dcb4-4983-4ee5-b8a2-ae384f6fc4e5\n  # Logging into http://localhost:8080/auth as user admin of realm master\n  # Created new realm with id 'demo'\n  # Created new client-scope with id '706cd55d-0c22-4596-bdfe-ee9e35bc5c73'\n  # Created new client with id '619b7a78-61eb-4d98-8bce-0b85801d36f6'\n  # Created new role with id 'ROLE_USER'\n  # Created new role with id 'ROLE_ADMIN'\n  # Created new user with id '2dac543f-7c8a-4a89-9487-c054f03a2a5b'\n  # Created new user with id 'e06db8fc-e401-424f-803e-8191abe8857c'\n  ```\n\n* Verify that `demo` realm and users exist in Keycloak.\n  ![keycloak-demo-realm.png](./_docs/img/keycloak-demo-realm.png)\n\n* Start resource server.\n  ```shell\n  ./gradlew bootRun\n  ```\n  \n* Import postman collection (`demo.postman_collection.json`).\n\n* Get the OAuth Access Token from Postman.\n  ![postman-get-oauth-token.png](./_docs/img/postman-get-oauth-token.png)\n  \n* Use **demo_user/demo_user** or **demo_admin/demo_admin** credentials inside Keycloak login popup.\n\n* Play with API.\n\n* Stop demo and cleanup volumes.\n  ```shell\n  docker-compose down -v\n  ```\n\n## Additional tips\n\n### Record stub mappings using WireMock\n\n* Download wiremock-standalone.jar e.g. https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.27.2/wiremock-standalone-2.27.2.jar\n\n* Start WireMock in a proxy mode to record calls to Keycloak.\n  ```shell\n  java -jar wiremock-standalone-2.27.2.jar --record-mappings --proxy-all=\"http://localhost:8081\"\n  ```\n\n* Recorded mappings can be found inside **mappings** and **__files**. These recordings can be useful for integration testing e.g. [HelloControllerTest](./src/test/java/com/rbiedrawa/oauth/web/HelloControllerTest.java)\n\n## References\n\n* [Spring Webflux Oauth2](https://docs.spring.io/spring-security/site/docs/5.2.0.M2/reference/html/webflux-oauth2.html)\n* [EnableReactiveMethodSecurity - Spring Security Documentation](https://docs.spring.io/spring-security/site/docs/5.1.1.RELEASE/reference/html/jc-erms.html)\n* [Reactive Test Support](https://docs.spring.io/spring-security/site/docs/5.1.1.RELEASE/reference/html/test-webflux.html)\n* [jwt.io](https://jwt.io/)\n* [Use Postman to test API calls](https://developer.mypurecloud.com/api/rest/postman/index.html#enable_authorization)\n* [Explain it to Me Like I’m 5: Oauth2 and OpenID](https://www.youtube.com/watch?v=5th6CSQTdpM)\n* [How to secure your Spring apps with Keycloak by Thomas Darimont @ Spring I/O 2019](https://www.youtube.com/watch?v=KrOd5wIkqls)\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbiedrawa%2Fspring-webflux-keycloak-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbiedrawa%2Fspring-webflux-keycloak-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbiedrawa%2Fspring-webflux-keycloak-demo/lists"}