Skip to content

fix(iOS): Handle NSNull in iosCustomBrowser param for logout #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

seanfar
Copy link

@seanfar seanfar commented Apr 25, 2025

Description

While there isn't an issue created specifically for what this PR is attempting to address, there are a few issues that seem to be related to it.

#1061 for example, which led to the fix introduced by #1064 addressed an issue on the authorize function.

Unfortunately, the logout function is still failing to properly display the browser, causing the flow to silently fail when iosCustomBrowser is not provided, as the call to [self getCustomBrowser:NSNull] returns nil.

This seems to be happening on RN V0.77.1 with the new architecture enabled. Untested on other versions.

This PR adds a guard to fallback to the default external user agent when iosCustomBrowser is nil or NSNull.

Steps to verify

  1. Configure the configuration object with no value for the iosCustomBrowser option that includes:
const config = {
  issuer: "https://youridprovider.com",
  clientId: "yourClientID",
  redirectUrl: "yourapp://callback",
  scopes: ["openid"],
  iosPrefersEphemeralSession: true,
  usePKCE: true,
};
  1. Add the calls accordingly for authorize(config) and logout(config) in your code.
  2. Build the app in iOS release mode.
  3. Execute the authorize (login) and logout calls via your application.
  4. Observe that the default browser is displayed properly.

Copy link

changeset-bot bot commented Apr 25, 2025

⚠️ No Changeset found

Latest commit: ee7a295

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Apr 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-app-auth ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 25, 2025 5:01pm

@sepperousseau
Copy link

@seanfar I tested it, it fixes the problem for me. Thanks! 👍

@seanfar seanfar changed the title fix: Handle NSNull in iosCustomBrowser param for logout fix(iOS): Handle NSNull in iosCustomBrowser param for logout May 7, 2025
@zibs zibs requested a review from Copilot May 27, 2025 16:40
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@zibs zibs requested a review from Copilot May 27, 2025 16:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue in the logout flow on iOS by ensuring that a custom browser parameter handles NSNull values appropriately.

  • Adds a conditional check to verify that iosCustomBrowser is not nil or NSNull.
  • Falls back to the default external user agent when the custom browser parameter is invalid.
Comments suppressed due to low confidence (1)

packages/react-native-app-auth/ios/RNAppAuth.m:522

  • Ensure that there are corresponding tests covering the scenario where iosCustomBrowser is NSNull to prevent regressions.
externalUserAgent = [self getCustomBrowser:iosCustomBrowser];

id<OIDExternalUserAgent> externalUserAgent = iosCustomBrowser != nil ? [self getCustomBrowser: iosCustomBrowser] : [self getExternalUserAgentWithPresentingViewController:presentingViewController
prefersEphemeralSession:prefersEphemeralSession];
id<OIDExternalUserAgent> externalUserAgent;
if (iosCustomBrowser != nil && ![iosCustomBrowser isEqual:[NSNull null]]) {
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the null/NSNull check for iosCustomBrowser into a helper method to improve code readability and reuse.

Suggested change
if (iosCustomBrowser != nil && ![iosCustomBrowser isEqual:[NSNull null]]) {
if ([self isNonNullObject:iosCustomBrowser]) {

Copilot uses AI. Check for mistakes.

@zibs
Copy link
Contributor

zibs commented May 27, 2025

Hey there @seanfar, I'm trying to reproduce the error locally but don't seem to be able too. Can you verify I'm following the right steps?

I am on a more updated RN version with new arch:

"react": "19.0.0",
"react-native": "0.79.2",

my config is;

    issuer: 'https://demo.duendesoftware.com',
    clientId: 'interactive.public',
    redirectUrl: 'io.identityserver.demo:/oauthredirect',
    additionalParameters: {},
    scopes: ['openid'] as const,
    iosPrefersEphemeralSession: true,
    usePKCE: true,

and I am running in release mode on iOS:

Screen.Recording.2025-05-27.at.10.11.28.AM.mp4

@zibs zibs self-assigned this May 27, 2025
@zibs zibs added needs-more-info This issue may not have sufficient information for a contributor to take action needs-repro This issue could be improved with a clear list of steps to reproduce the issue labels May 27, 2025
@seanfar
Copy link
Author

seanfar commented May 28, 2025

Hey there @seanfar, I'm trying to reproduce the error locally but don't seem to be able too. Can you verify I'm following the right steps?

I am on a more updated RN version with new arch:

"react": "19.0.0",
"react-native": "0.79.2",

my config is;

    issuer: 'https://demo.duendesoftware.com',
    clientId: 'interactive.public',
    redirectUrl: 'io.identityserver.demo:/oauthredirect',
    additionalParameters: {},
    scopes: ['openid'] as const,
    iosPrefersEphemeralSession: true,
    usePKCE: true,

and I am running in release mode on iOS:

Hey thanks for the response and testing @zibs -

No, that seems correct. I haven't revisited this after I posted, but since then it seems the documentation for migrating to AppDelegate.swift has been added here.

My gut tells me there's likely some discrepancy between what we currently have setup in our project and what's outlined there, as we had migrated it by hand before these instructions existed. We started seeing this issue after a library + RN upgrade to 0.77.

I'll double and triple check. If it's on our end, I'll make sure to close this PR out. But if we're still seeing issues, I'll try to get you a minimal repro as soon as possible. Thank you again!

@zibs
Copy link
Contributor

zibs commented May 28, 2025

Sounds great, thank you!

@seanfar
Copy link
Author

seanfar commented May 30, 2025

@zibs

following up as promised. After ensuring our AppDelegate.swift was setup according to the docs, it seems like this is working as expected. The issue was on our end. Apologies for any time wasted trying to repro this, I'll go ahead and close it out.

still curious how we weren't the only ones seeing this in our project, but it could very well be something similar.

cc: @sepperousseau - you may want to verify your project is setup correctly as well. Happy to help however I can.

thank you both again!

@seanfar seanfar closed this May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-info This issue may not have sufficient information for a contributor to take action needs-repro This issue could be improved with a clear list of steps to reproduce the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants