5

I am authenticating our web service using ASWebAuthenticationSession and for some reason the only option after the final redirect is Cancel. I had this working before where even if I did press Cancel, the callback Url was sent through the completion handler and I was able to parse the token form there. But now I just get the error ASWebAuthenticationSessionErrorCodeCanceledLogin.

How do I get the ASWebAuthenticationSession to show the Done button and complete the handler with the callback Url? Did something change or break in the last iOS update?

How I create the session

if (@available(iOS 12.0, *)) {
    self.session = [[ASWebAuthenticationSession alloc]
                    initWithURL:@"http://service.com"
                    callbackURLScheme:@"http://website.com"
                    completionHandler:_sessionHandler];
     [self.session start];
}

Completion handler

_sessionHandler = ^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {
    NSLog(@"Callback Url: %@, Error: %@", callbackURL, error);
    if ( callbackURL != nil ) {
        __block NSString * token = [weakSelf webToken:@"token" fromUrl:callbackURL];
        weakSelf.completionHandler([weakSelf parseWebToken:token], error);
    }
    else
        weakSelf.completionHandler(nil, error);
};

The output

Callback Url: (null), Error: Error Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=1 "(null)"

enter image description here

Like I mentioned, this worked previously and I am not sure where it broke. The test service I used has not changed, so I am wondering if it is in the framework, or if I am missing something else.

Should the web service be sending a specific header back to the final Url so ASWebAuthenticationSession will show the Done button and complete the handler with the Url?

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • Hi did you find the solutuon – iOSDeveloper Oct 28 '20 at 07:49
  • Just a quick question, Is it possible to customize the navigation bar which appears with the button items, Cancel, reload icon, etc. to some controls of our own? Please help if you find any solution :) – user2580 May 21 '21 at 09:39

0 Answers0