ASWebAuthenticationSession only shows Cancel button

1.3k Views Asked by At

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?

0

There are 0 best solutions below