In my iOS app I authenticate users with Keycloak through the AppAuth library. There is a situation where I want to open a webview in my app and have the user be logged in. My idea was to somehow fetch the cookies from Keycloak and set them on the webview before presenting it to the user.
To test this I’ve logged in using a browser and copied the AUTH_SESSION_ID, KEYCLOAK_IDENTITY and KEYCLOAK_SESSION and set them on the webview:
let authCookie = HTTPCookie(properties: [
.domain: "my-keycloak.host.org",
.path: "/realms/my-realm/",
.name: "AUTH_SESSION_ID",
.value: "auth-session-cookie-value",
.secure: "TRUE",
.expires: "Session"
])!
webView.configuration.websiteDataStore.httpCookieStore.setCookie(authCookie)
But this doesn’t seem to work. Is this the best way to have a user be logged in in a webview after they have already logged in using the AppAuth library or is there a better way?