Hi,
I’m not sure if I totally understand your questions so I’ll try to answer anyway.
Keycloak is a SSO solution that uses OpenID Connect which is built on top of OAuth2 (in other words it does more than just OAuth2).
In Oauth2 you usually configure your Keycloak to one of the possible flows:
When you’re developing web applications where the auth happens at the server side (your vert.x code) you should choose “Private”. In this case you’re using the AUTH_CODE flow.
The example you saw was using this and you can either use it without sessions and redirects are required, or you can enable the session handler and your browser will remember you. For this you will need:
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
// you can put your auth handler here
router.route().handler(UserSessionHandler.create(authProvider));
Now you’re refering to keep the session client side, by this I think you’re speaking on single page applications. When using this mode you should configure keycloak for the Public flow. and then authenticate using JS skipping all this vert.x setup.
You should refer to this doc: https://keycloak.gitbooks.io/documentation/securing_apps/topics/oidc/javascript-adapter.html
Now everything is handler at the web client side, so on your backend you have 2 choices:
Either configure OAuth2 handler for keycloak or just use the JWTAuthHandler since all you need now is to parse the token the js script got for you.
The important part here is that your js client code when doing AJAX calls should add the correct headers, something like:
var req = new XMLHttpRequest();
// add the required headers
req.setRequestHeader('Accept', 'application/json');
req.setRequestHeader('Authorization', 'Bearer ' + keycloak.token);
...
OAuth2Auth keyCloakAuthProvider = KeycloakAuth.create(vertx, keycloakJson);
OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(keyCloakAuthProvider, "http://localhost:8081");
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
oauth2.setupCallback(router.get("/callback"));
router.route().handler(oauth2);
router.route().handler(UserSessionHandler.create(keyCloakAuthProvider));
// Here comes the real content....
router.route("/products")......