Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created July 20, 2017 13:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasdarimont/ca16080145d226e50628d5696ffb9508 to your computer and use it in GitHub Desktop.
Save thomasdarimont/ca16080145d226e50628d5696ffb9508 to your computer and use it in GitHub Desktop.
Simple Authentication for Desktop apps with Keycloak.
{
"realm": "local-user-import",
"auth-server-url": "http://192.168.99.1:8080/u/auth",
"ssl-required": "external",
"resource": "app-edrewe",
"credentials": {
"secret": "29ddfb71-53fa-446d-aed5-2ce6de1fe490"
},
"use-resource-role-mappings": true
}
package demo;
import org.keycloak.adapters.installed.KeycloakInstalled;
import org.keycloak.representations.AccessToken;
public class Main {
public static void main(String[] args) throws Exception {
KeycloakInstalled keycloak = new KeycloakInstalled();
keycloak.loginDesktop();
System.out.println("Logged in...");
AccessToken token = keycloak.getToken();
System.out.printf("UserId: %s%n", token.getSubject());
System.out.printf("Username: %s%n", token.getPreferredUsername());
System.out.printf("Email: %s%n", token.getEmail());
System.out.println(keycloak.getTokenString());
System.in.read();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment