[keycloak-user] Keycloak AJAX authentication flow

Bartosz Andrzejczak ba.andrzejczak at gmail.com
Tue Feb 20 15:43:17 EST 2018


Hi Moritz,

The usual path with SPA would be to just redirect user to the Keycloak authentication page, that if user’s logged in would just redirect them back with authentication code in the query parameter, and if not - would require user to log in. I’ve described that for Angular here: https://medium.com/andrzejczak/sso-for-your-single-page-application-part-1-2-angularjs-1d79edb7d9c8 <https://medium.com/andrzejczak/sso-for-your-single-page-application-part-1-2-angularjs-1d79edb7d9c8>

But if your app load time is quite long there might be something else you can do. There’s a token endpoint that would return you a JSON containing authentication token and refresh token, both with expiration times. All you need to provide is login and password (and additionally grant_type (`password`) and your client_id). So if you decide to implement authentication form on your side you could just use that to get a token for a user and treat this user as logged into the application. You’re loosing the SSO capabilities of Keycloak, but it might still be enough for you. You can see example of this token request in step 1 of this blogpost https://blog.softwaremill.com/who-am-i-keycloak-impersonation-api-bfe7acaf051a <https://blog.softwaremill.com/who-am-i-keycloak-impersonation-api-bfe7acaf051a>. Be sure to enable Direct Flow in the Keycloak Client, though.

Cheers,
Bartek

> On 20 Feb 2018, at 3:38 PM, <moritz.becker at gmx.at> <moritz.becker at gmx.at> wrote:
> 
> Hi,
> 
> 
> 
> I am trying to implement a Keycloak registration theme using the Aurelia JS
> Framework.
> 
> 
> 
> The problem is that there is currently no possibility to submit the
> registration form via AJAX and get back a reduced response that just
> contains validation errors etc. instead of reloading the whole page. Page
> reload is problematic in this scenario since it causes a reload of the
> Aurelia-App which takes too long.
> 
> 
> 
> As far as I can see, I would need to customize the
> org.keycloak.authentication.FormAuthenticationFlow but there is not SPI to
> do so at the moment.
> 
> 
> 
> Do you have any recommendations for me?
> 
> 
> 
> Thanks, 
> 
> Moritz
> 
> 
> 
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user



More information about the keycloak-user mailing list