Konubinix' opinionated web of thoughts

Develop an Android Application Using Keycloak and Localhost Redirection


develop an android application using keycloak and localhost redirection

I tend to like using a dev env similar to the prod env, so I suppose I’m using a local k8s cluster with https handled by cert-manager.

I suppose as well that the site is available in this local cluster using the standard url localtest.me.

By default, the localhost of the android device is its own localhost. The host localhost is available using

Run the emulator and apply a port reversing using.

adb root
adb reverse tcp:443 tcp:443

That’s all. The traffic going to https://myapp.localtest.me should be revered into your host’s localhost and dealt with correctly with keycloak.

If you unfortunately use a localhost subdomain, like https://myapp.localhost, you will also need to make this allow subdomains, using some network security stuff.

Also, you might be tempted to edit /etc/hosts to make myapp.localhost point towards Yet, in my experience, this is an unstable solution because the browser make special handling for some regexps.

For instance, myapp.something -> works, while myapp.localhost -> does not1. Also, there are files in /etc/hosts, /etc/system/hosts and /system/etc/hosts, making it difficult to be sure you are editing the right one.

  1. this is likely a special handling made by the browser itself. ping myapp.localhost shows the ip as expected and still the browser won’t use it somehow. ↩︎