Closed wieczorekmarcin closed 4 years ago
@wieczorekmarcin are you getting any error in your console?
I am not familiar with these platforms but if they operate in an environment without access the DOM it will not work as the library we depend on keycloak-js
does not support this.
This time I initialized keycloak-angular with ng Bootstrap. I haven't set up redirectURI either - previously it was the address for my mobile application with the custom scheme, e.g. myapp: // callback. This time I received other results:
default adapter:
Channel not fired: onDOMContentLoaded
Ionic Native: deviceready did not fire within 5000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins / and reinstalling them.
cordova-native adapter
vendor.js: 43187 ERROR Error: Uncaught (in promise): ReferenceError: universalLinks is not defined
ReferenceError: universalLinks is not defined
Universal Links Plugin does not exist for Capacitor, instead there is Deeplinks Plugin https://ionicframework.com/docs/native/deeplinks
codova adapter
TypeError: Cannot read property 'code' of undefined
at processCallback (: 8100 / vendor.js: 118056)
at Channel. <anonymous> (: 8100 / vendor.js: 118694)
at Channel.fire (: 8100 / capacitor-runtime.js: 1844)
at InAppBrowser._eventHandler (: 8100 / capacitor-runtime.js: 2767)
at cb (: 8100 / capacitor-runtime.js: 2832)
at Object.callbackFromNative (: 8100 / capacitor-runtime.js: 1338)
at <anonymous>: 1: 9
capacitor.handleError @ capacitor-runtime.js: 362
I can make authorized requests (with the correct authorization header). Everything except this error looks ok.
@wieczorekmarcin It looks like this is a larger problem combining Capacitor with keycloak-js
see this thread in the mailing list.
I'd recommend creating an issue in the Keycloak issue tracker, the team tends to respond to those as well.
For now I am going to close this issue here, as there is not much we can do until this is resolved upstream.
@wieczorekmarcin It's possible to create your own adapter for Capacitor, for more information on how to pass in a custom adapter to Keycloak see: https://github.com/keycloak/keycloak/pull/7168
Did anybody manage to do this ? I'm currently searching for a library working with Keycloak for a Ionic 5 + capacitor app
Any news on this?
There is to ways that I found:
const keycloak = new Keycloak(...)
keycloak.init({
...,
adapter: {
// custom adapter implementation
}
})
const keycloakOptions: KeycloakOptions = {
config: {
url: 'http://localhost:9080/auth',
realm: 'jhipster',
clientId: 'web_app'
},
initOptions: {
onLoad: 'login-required',
checkLoginIframe: false
},
enableBearerInterceptor: true,
bearerExcludedUrls: ['/assets']
};
export const environment = { production: false, keycloakOptions, ... };
export class AppModule implements DoBootstrap { async ngDoBootstrap(app) { try { await keycloakService.init(environment.keycloakOptions); app.bootstrap(AppComponent); } catch (error) { console.error('Keycloak init failed', error); } } }
I hope this helps you!
Sorry for replying to an already closed issue but could you give me some hints/helpful links or documentation on how to create the custom adapter (custom adapter implementation). I just convinced some people to use keycloak for our ionic app instead of doing authentication on our own and didn't realize that it isn't that easy with capacitor.
@wieczorekmarcin could you share the code for your custom capacitor adapter ?
@jonkoops @christian-kocke @wieczorekmarcin @tuxflo @enlight3d @broth-eu, have you managed to solve this? I've a kinda working demo at https://github.com/edgeflare/edge-ui, but it's certainly not fit for production. Please help us improve https://github.com/edgeflare/edge-ui/blob/master/src/app/keycloak.service.ts. Also, I'm attempting a framework agnostic Capacitor adaptor https://github.com/edgeflare/edge-ui/blob/master/docs/capacitor-keycloak-adapter.ts
Bug Report or Feature Request (mark with an
x
)Versions.
Is there any way to set up keycloak-angular with Ionic 5 and Capacitor 2? If so, could I have a configuration example? I think I tried everything (adapters, onLoad and flow types) and I was unable to log in and log out correctly using keycloak.
Thank you in advance for your help.