CRoig
CRoig

Reputation: 693

SFAuthenticationSession completion handler not called

I am trying to implement an approach to exchange cookies from Safari and App. I am using SFAuthenticationSession since the cookies sharing was disabled. I read through the topic and it seems this is the best solution to achieve this. There are not too many blogs or repos to use as an example.

I have implemented the changes redirect in the server side as following.

First I store the cookie as https://example.com/?cookie=12345. Then from the app I start an Authentication Session pointing to https://example.com/getcookie which redirects to customapp://dummy/cookies?cookie=12345

Once stated this. The swift implementation is the following (thanks to this):

let callbackUrl  = "customapp://dummy/cookies"
let authURL = "https://example.com/getcookie"

self.authSession = SFAuthenticationSession(url: URL(string: authURL)!, callbackURLScheme: callbackUrl, completionHandler: { (callBack:URL?, error:Error? ) in
    guard error == nil, let successURL = callBack else {
        return
    }

    let cookie = self.parseQuery(url: (successURL.absoluteString), param: "cookie")
    print(cookie!)

    })

self.authSession?.start()

You may notice I am not interested on signing in but getting a cookie stored previously.

Can anyone please advice? My problem is that although the site is redirecting, the completion handler is not called, so I can't parse the callback url.

UPDATE

I found out I was missing the protocol in the Info.plist. After adding the custom protocol to it, the handler was called. Nevertheless, the handler was only called the second time I engaged the Authentication Session.

Any clue?

Upvotes: 5

Views: 1681

Answers (0)

Related Questions