AppAuth-iOS icon indicating copy to clipboard operation
AppAuth-iOS copied to clipboard

SSO App & Website (Question)

Open merzchr opened this issue 5 years ago • 15 comments

Dear AppAuth-iOS Community, is there a possibility to remember my OIDC credentials when im switching between native iosApp & common Safari Browser on my ios device?

merzchr avatar Feb 05 '20 09:02 merzchr

Hi guys, i have to push this topic again. If some is interested in a consulting project here. It would be great to get a message. Best Christsian

merzchr avatar Feb 12 '20 09:02 merzchr

Let's dissect this a bit, shall we?

When using AppAuth in your iOS App, you would start your authentication:

let authorizationRequest = OIDAuthorizationRequest(....)

OIDAuthState.authState(byPresenting: authorizationRequest) { authState, authError in 
    // handle authState or error
}
Safari Authentication Session
safari-auth-session

Under the hood, this will use SFAuthenticationSession (iOS 11) or ASWebAuthenticationSession (iOS 12+). Both sessions will open a Safari View-Controller within the context of your app. This Safari instance has access to the global iOS cookie and session cache.

That's the same cookie and session cache that the default iOS Safari browser app is using. So, if your user is authenticating either in the Safari browser app or in your app (via the mentioned XY-AuthenticationSession), you will have access to the user's session.

leviathan avatar Feb 18 '20 08:02 leviathan

Hi Leviathan,

but that is only true if it's a persistent cookie and not a session cookie. Also if you somehow need to add web content inside ob the app (inAppBrowsing with SafariViewController or WKWebView), that would not work as well if we have SFAuthenticationSession (iOS 11) or ASWebAuthenticationSession (iOS 12+).

So for that case i don't see any solution or does somebody has an idea how it would be possible to solve this?

Markus-Sky avatar Feb 18 '20 13:02 Markus-Sky

Hi Leviathan, Markus mentioned exactly my challenge :/ Best Christian

merzchr avatar Feb 21 '20 13:02 merzchr

Hi, looks like I'm facing the same issue.

pertau avatar Feb 27 '20 08:02 pertau

Hi guys, Do you know if there is a way to not use SFSafariViewController and open Safari app instead?

juancarlosdmz avatar Mar 10 '20 14:03 juancarlosdmz

Hi guys, Do you know if there is a way to not use SFSafariViewController and open Safari app instead?

Apple will likely reject your application if you use Safari instead of SFAuthenticationSession or ASWebAuthenticationSession.

karimhm avatar May 31 '20 00:05 karimhm

I second the above. Expectation is when I logged in on iOS app and the WebView controller launches, it should have save the cookie as persistent, so that when I access my web app on Safari, it should be able to read the cookie and logged in automatically.

On AppAuth-Android, the behavior is working correctly. Only here in iOS the cookie is session based. Is there anyway configuration to make the cookie persistent?

vvavepacket avatar Aug 16 '20 03:08 vvavepacket

Hi guys, I am facing the same issue, maybe some one have resolve this issue?

dattran-pt19 avatar May 10 '22 08:05 dattran-pt19

Hi, did anyone found a solution please ?

KevinGiacomino avatar Jan 25 '23 17:01 KevinGiacomino

I did quite some testing for SSO between browser and app using an ASWebAuthenticationSession and setting prefersEphemeralWebBrowserSession to false. Based on this article https://developer.okta.com/blog/2022/01/13/mobile-sso#sfauthenticationsession-or-aswebauthenticationsession-behavior and the Apple docs (https://developer.apple.com/documentation/authenticationservices/authenticating_a_user_through_a_web_service#3395310) that should be possible.

my reproduction path:

  1. using iPhone 15 pro emulator, OS version 17.2
  2. take the example project (https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth/example) and change preferEphemeralSession to be false (it's flutter but under the hood used AppAuth-iOS)
  3. open Safari on the emulator on https://demo.duendesoftware.com/Account/Login
  4. login with bob/bob and check the 'remind me' box (important, otherwise you will get a session cookie)
  5. now there is persistent cookie named idsrv with an age of 1 month
  6. open the example app
  7. click 'sign in no code exchange'
  8. now the login window is showing while I would expect the persistent cookies to present and Identity server to automatically redirect.

This is the ASWebAuthenticationSession when debugging: Screenshot 2024-01-24 at 09 31 22

Here is a comparision between the cookies in Safari vs. the cookies in the webview: Screenshot 2024-01-24 at 11 25 34

Conclusion: For some reason the cookies are not shared between Safari en the Webview, but not sure why...

lazytesting avatar Jan 24 '24 10:01 lazytesting