google / GoogleSignIn-iOS

Enables iOS and macOS apps to sign in with Google.
https://developers.google.com/identity/sign-in/ios
Apache License 2.0
506 stars 201 forks source link

Ephmeral session or how to clear logged in state in WKWebView after logout? #294

Open bezig01 opened 1 year ago

bezig01 commented 1 year ago

Describe the bug I'm wondering how to enable ephemeral session using Google SignIn? Or how to correctly clear cookies in WKWebView after Google SignIn signOut() method?

To Reproduce Steps to reproduce the behavior:

  1. Login using Google SignIn
  2. Opens WKWebView with no google account signed in (email field is cleared)
  3. After entering credentials and successful login try to logout
  4. Login again
  5. Opens WKWebView with cached google account

Expected behavior (5) Opens WKWebView with no google account signed in (email field is cleared)

Screenshots none

Environment

Additional context I tried to clear cookies

  1. In iOS Settings-Safari-Clear History and Website Data

  2. Programmatically:

    func clearAllCookies() {
    
         let url = URL(string: "https://accounts.google.com/Logout")!
         UIApplication.shared.open(url, options: [:], completion: nil)
    
        if let cookies = HTTPCookieStorage.shared.cookies, cookies.count > 0 {
            HTTPCookieStorage.shared.removeCookies(since: .distantPast)
            print("All cookies deleted")
        }
    
        let dataStore = WKWebsiteDataStore.default()
        dataStore.fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
            records.forEach { record in
                dataStore.removeData(ofTypes: record.dataTypes, for: [record], completionHandler: {
                    print("Deleted:", record)
                })
            }
        }
    }

None of the above worked.

bezig01 commented 1 year ago

It seems a bit difficult to enable prefersEphemeralWebBrowserSession as per https://github.com/openid/AppAuth-iOS/issues/542

bezig01 commented 1 year ago

I need to add details. As I was using corporate email with strict policy so when I tried to login it shows login issues and then I can never log out. Simulator Screen Shot - iPhone 14 Pro - 2023-02-03 at 11 57 26