{"id":15351109,"url":"https://github.com/realityforge/gwt-keycloak","last_synced_at":"2025-04-15T02:37:00.574Z","repository":{"id":57739978,"uuid":"71099147","full_name":"realityforge/gwt-keycloak","owner":"realityforge","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-26T02:53:47.000Z","size":354,"stargazers_count":11,"open_issues_count":4,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T15:01:50.115Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/realityforge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2016-10-17T04:09:47.000Z","updated_at":"2024-12-20T08:25:02.000Z","dependencies_parsed_at":"2024-10-01T12:01:19.664Z","dependency_job_id":"660ba75b-b7cc-41b5-a61b-9a72ea765744","html_url":"https://github.com/realityforge/gwt-keycloak","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realityforge%2Fgwt-keycloak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realityforge%2Fgwt-keycloak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realityforge%2Fgwt-keycloak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realityforge%2Fgwt-keycloak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realityforge","download_url":"https://codeload.github.com/realityforge/gwt-keycloak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248995101,"owners_count":21195497,"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","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":[],"created_at":"2024-10-01T12:01:07.302Z","updated_at":"2025-04-15T02:37:00.295Z","avatar_url":"https://github.com/realityforge.png","language":"Java","funding_links":[],"categories":["Auth and Security"],"sub_categories":[],"readme":"# gwt-keycloak\n\n[![Build Status](https://api.travis-ci.com/realityforge/gwt-keycloak.svg?branch=master)](http://travis-ci.com/realityforge/gwt-keycloak)\n[\u003cimg src=\"https://img.shields.io/maven-central/v/org.realityforge.gwt.keycloak/gwt-keycloak.svg?label=latest%20release\"/\u003e](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.realityforge.gwt.keycloak%22%20a%3A%22gwt-keycloak%22)\n\nA simple library to provide keycloak support to GWT. The library wraps and adapts the\n[keycloak adapter](https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter)\nthat is deployed on the keycloak server.\n\n## Quick Start\n\nThe simplest way to use the library is to add the following dependency\ninto the build system. i.e.\n\n```xml\n\u003cdependency\u003e\n   \u003cgroupId\u003eorg.realityforge.gwt.keycloak\u003c/groupId\u003e\n   \u003cartifactId\u003egwt-keycloak\u003c/artifactId\u003e\n   \u003cversion\u003e0.14\u003c/version\u003e\n   \u003cscope\u003eprovided\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nThen you add the following snippet into the .gwt.xml file.\n\n```xml\n\u003cmodule rename-to='myapp'\u003e\n  ...\n\n  \u003c!-- Enable the keycloak library --\u003e\n  \u003cinherits name=\"org.realityforge.gwt.keycloak.Keycloak\"/\u003e\n\u003c/module\u003e\n```\n\nThen you can interact with the Keycloak object from within the browser.\n\nFirst you need to setup a Keycloak instance. Assuming your keycloak server has an application client\nnamed `\"MyApp\"` and the configuration json is at `http://127.0.0.1:8080/myapp/keycloak.json` then you\nend up with code like:\n\n```java\nfinal Keycloak keycloak = new Keycloak( \"MyApp\", \"http://127.0.0.1:8080/myapp/keycloak.json\" );\n\nkeycloak.setListener( new KeycloakListenerAdapter()\n{\n  @Override\n  public void onReady( @Nonnull final Keycloak keycloak, final boolean authenticated )\n  {\n    if( authenticated )\n    {\n      //Already authenticated, start app here\n    }\n    else\n    {\n      keycloak.login();\n    }\n  }\n} );\n\nkeycloak.init();\n```\n\nWhen the token is needed to interact with a keycloak protected resource you can simply use the following\ncode to access the current token, updating it if it is stale and needs to be refreshed.\n\n```java\nfinal int minTokenValiditySeconds = 30;\nkeycloak.updateToken( minTokenValiditySeconds, () -\u003e remoteCallUsingToken( keycloak.getToken() ) );\n```\n\nThis should be sufficient to put together a simple Keycloak application.\n\n## Quick Start using token caching\n\nYou can also use the library to cache tokens local in web storage apis (i.e. local storage or session\nstorage if available). These tokens will be revalidated locally and updated (assuming you use the correct\nlistener) when necessary. This results in a much better user experience as the network overhead is significantly\nreduced.\n\nFirst you add dependency as above, then you add a snippet like the following into the `.gwt.xml` file.\n\n```xml\n\u003cmodule rename-to='myapp'\u003e\n  ...\n\n  \u003c!-- Enable the keycloak library --\u003e\n  \u003cinherits name=\"org.realityforge.gwt.keycloak.cache.TokenCache\"/\u003e\n\u003c/module\u003e\n```\n\nThe code to interact with the backend looks something like:\n\n```java\n\nfinal Keycloak keycloak = new Keycloak( \"MyApp\", \"http://127.0.0.1:8080/myapp/keycloak.json\" );\nTokenCache.configure( keycloak );\n\nkeycloak.setListener( new TokenCachingListener()\n{\n  @Override\n  public void onReady( @Nonnull final Keycloak keycloak, final boolean authenticated )\n  {\n    super.onReady( keycloak, authenticated );\n    if( authenticated )\n    {\n      //Already authenticated, start app here\n    }\n    else\n    {\n      keycloak.login();\n    }\n  }\n} );\n\nkeycloak.init();\n```\n\n## Appendix\n\n* [Keycloak Javascript Adapter](https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealityforge%2Fgwt-keycloak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealityforge%2Fgwt-keycloak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealityforge%2Fgwt-keycloak/lists"}