AppAuth-iOS: iOS Obj-C presentEndSessionRequest callback not getting called

Describe the bug When using iOS Objective-C presentEndSessionRequest, one of the parameters is ‘callback’. However, even though the call seems to succeed (the OAuth credentials are reset) and the annoying ‘Sign In’ alert appears (#643), the callback doesn’t get called.

Expected behavior I expect the callback to be called. 😉

Smartphone

  • Device: iPhone 8 although with the Xcode simulator I’ve tried other iPhone versions
  • OS: 15.4 (and others)
  • Browser: the OAuth flow appears to use Safari

Here is the code I’m using in case it helps, where logoutRedirectURL is obfuscated. I’ve tried with and without the additionalParameters.

#define logoutRedirectURL @"com.mydomain.mobile:/logout"

        NSString *issuerURL = [[NSString stringWithString:currentAccount.serverName] lowercaseString];
        NSURL *url = [NSURL URLWithString:issuerURL];
        issuerURL = [NSString stringWithFormat:@"%@/auth/realms/%@", issuerURL, url.host];
        NSURL *issuer = [NSURL URLWithString:issuerURL];
        
        [OIDAuthorizationService discoverServiceConfigurationForIssuer:issuer
            completion:^(OIDServiceConfiguration *_Nullable configuration, NSError *_Nullable error) {
            if (configuration) {
                // build end session request
                NSURL *redirectURL = [NSURL URLWithString:logoutRedirectURL];
                NSDictionary *additionalParameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:logoutRedirectURL, currentAccount.idToken, nil]
                    forKeys:[NSArray arrayWithObjects:@"post_logout_redirect_uri", @"id_token_hint", nil]];
                
                OIDEndSessionRequest *request = [[OIDEndSessionRequest alloc] initWithConfiguration:configuration idTokenHint:currentAccount.idToken postLogoutRedirectURL:redirectURL
                    additionalParameters:additionalParameters];
                OIDExternalUserAgentIOS *agent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:self];
                [OIDAuthorizationService presentEndSessionRequest:request externalUserAgent:agent callback:^(OIDEndSessionResponse * _Nullable endSessionResponse, NSError * _Nullable error) {
                    // note: this callback never seems to happen...
                    if (endSessionResponse) {
                    } else {
                        VLog(@"endSession error: %@", [error localizedDescription]);
                    }
                }];
            }
        }];

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21

Most upvoted comments

We faced a similar issue where we couldn’t log out despite using correct redirect uri, endpoint etc. What solved it for us was assigning presentEndSessionRequest to a variable. I haven’t figured why it works, or if it’s the correct way, but it somehow works. ¯_(ツ)_/¯

Example (in Swift) private let userAgentSession: OIDExternalUserAgentSession? init() { userAgentSession = nil } self.userAgentSession = OIDAuthorizationService.present(endSessionsRequest,...)

Facing the same issues:

  • application:openURL:options: delegate is not called.
  • app and OIDC provider is correctly setup with custom URL schemes
  • callback not being fired