From cd5b3afc588368b58a8b643bd83a13063b847857 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:33:16 -0700 Subject: [PATCH 1/5] g-orchestrated: add instance presenters and presenting getters --- .../AppAuth/iOS/OIDAuthorizationService+IOS.h | 23 +++++++++++++++ .../AppAuth/iOS/OIDAuthorizationService+IOS.m | 29 +++++++++++++++++++ .../iOS/OIDExternalUserAgentCatalyst.h | 4 +++ .../iOS/OIDExternalUserAgentCatalyst.m | 2 ++ Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h | 4 +++ Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m | 2 ++ .../macOS/OIDAuthorizationService+Mac.h | 23 +++++++++++++++ .../macOS/OIDAuthorizationService+Mac.m | 21 ++++++++++++++ .../AppAuth/macOS/OIDExternalUserAgentMac.h | 4 +++ .../AppAuth/macOS/OIDExternalUserAgentMac.m | 2 ++ 10 files changed, 114 insertions(+) diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h index c7c685d28..9aeb50517 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h @@ -60,6 +60,29 @@ NS_ASSUME_NONNULL_BEGIN prefersEphemeralSession:(BOOL)prefersEphemeralSession callback:(OIDAuthorizationCallback)callback API_AVAILABLE(ios(13)); +/*! @brief Instance counterpart of @c +presentAuthorizationRequest:presentingViewController:callback:. + @param request The authorization request. + @param presentingViewController The view controller from which to present authentication UI. + @param callback The method called when the request has completed or failed. + */ +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + callback:(OIDAuthorizationCallback)callback; + +/*! @brief Instance counterpart of + @c +presentAuthorizationRequest:presentingViewController:prefersEphemeralSession:callback:. + @param request The authorization request. + @param presentingViewController The view controller from which to present authentication UI. + @param prefersEphemeralSession Whether the caller prefers to use a private authentication + session. See @c ASWebAuthenticationSession.prefersEphemeralWebBrowserSession for more. + @param callback The method called when the request has completed or failed. + */ +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback + API_AVAILABLE(ios(13)); + @end NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m index 4ca07c55e..b761516ea 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m @@ -57,6 +57,35 @@ @implementation OIDAuthorizationService (IOS) return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; } +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + callback:(OIDAuthorizationCallback)callback { + id externalUserAgent; +#if TARGET_OS_MACCATALYST + externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] + initWithPresentingViewController:presentingViewController]; +#else // TARGET_OS_MACCATALYST + externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:presentingViewController]; +#endif // TARGET_OS_MACCATALYST + return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; +} + +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { + id externalUserAgent; +#if TARGET_OS_MACCATALYST + externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] + initWithPresentingViewController:presentingViewController + prefersEphemeralSession:prefersEphemeralSession]; +#else // TARGET_OS_MACCATALYST + externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:presentingViewController + prefersEphemeralSession:prefersEphemeralSession]; +#endif // TARGET_OS_MACCATALYST + return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; +} + @end NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.h b/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.h index 910d0bb86..e79f3f07f 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.h +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.h @@ -32,6 +32,10 @@ NS_ASSUME_NONNULL_BEGIN API_AVAILABLE(macCatalyst(13)) API_UNAVAILABLE(ios) @interface OIDExternalUserAgentCatalyst : NSObject +/*! @brief The view controller from which the authentication UI is presented. + */ +@property(nonatomic, readonly, nullable) UIViewController *presentingViewController; + /*! @internal @brief Unavailable. Please use @c initWithPresentingViewController: */ diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.m b/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.m index 4c10c154d..c57db89f7 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.m +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentCatalyst.m @@ -45,6 +45,8 @@ @implementation OIDExternalUserAgentCatalyst { ASWebAuthenticationSession *_webAuthenticationVC; } +@synthesize presentingViewController = _presentingViewController; + - (nullable instancetype)initWithPresentingViewController: (UIViewController *)presentingViewController { self = [super init]; diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h index c7916a52e..67b07b5e3 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h @@ -34,6 +34,10 @@ NS_ASSUME_NONNULL_BEGIN API_UNAVAILABLE(macCatalyst) @interface OIDExternalUserAgentIOS : NSObject +/*! @brief The view controller from which the authentication UI is presented. + */ +@property(nonatomic, readonly, nullable) UIViewController *presentingViewController; + - (null_unspecified instancetype)init API_AVAILABLE(ios(11)) __deprecated_msg("This method will not work on iOS 13, use " "initWithPresentingViewController:presentingViewController"); diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m index eac47acf5..7a6879c67 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m @@ -81,6 +81,8 @@ @implementation OIDExternalUserAgentIOS { #pragma clang diagnostic pop } +@synthesize presentingViewController = _presentingViewController; + - (null_unspecified instancetype)init { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnonnull" diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h index 0a34faf28..6cab9e9bf 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h @@ -71,6 +71,29 @@ NS_ASSUME_NONNULL_BEGIN callback:(OIDAuthorizationCallback)callback __deprecated_msg("For macOS 10.15 and above please use presentAuthorizationRequest:presentingWindow:callback:"); +/*! @brief Instance counterpart of @c +presentAuthorizationRequest:presentingWindow:callback:. + @param request The authorization request. + @param presentingWindow The window to present the authentication flow. + @param callback The method called when the request has completed or failed. + */ +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + callback:(OIDAuthorizationCallback)callback; + +/*! @brief Instance counterpart of + @c +presentAuthorizationRequest:presentingWindow:prefersEphemeralSession:callback:. + @param request The authorization request. + @param presentingWindow The window to present the authentication flow. + @param prefersEphemeralSession Whether the caller prefers to use a private authentication + session. See @c ASWebAuthenticationSession.prefersEphemeralWebBrowserSession for more. + @param callback The method called when the request has completed or failed. + */ +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback + API_AVAILABLE(macos(10.15)); + @end NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m index 4d3d9a038..aea3619fc 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m @@ -57,6 +57,27 @@ @implementation OIDAuthorizationService (Mac) callback:callback]; } +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + callback:(OIDAuthorizationCallback)callback { + OIDExternalUserAgentMac *externalUserAgent = [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow]; + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { + OIDExternalUserAgentMac *externalUserAgent = + [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow + prefersEphemeralSession:prefersEphemeralSession]; + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + @end NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuth/macOS/OIDExternalUserAgentMac.h b/Sources/AppAuth/macOS/OIDExternalUserAgentMac.h index 360c44ad6..d7e3c35a7 100644 --- a/Sources/AppAuth/macOS/OIDExternalUserAgentMac.h +++ b/Sources/AppAuth/macOS/OIDExternalUserAgentMac.h @@ -30,6 +30,10 @@ NS_ASSUME_NONNULL_BEGIN */ @interface OIDExternalUserAgentMac : NSObject +/*! @brief The window from which the authentication UI is presented. + */ +@property(nonatomic, readonly, nullable) NSWindow *presentingWindow; + /*! @brief The designated initializer. @param presentingWindow The window from which to present the @c ASWebAuthenticationSession on macOS 10.15 and above. Older macOS versions use the system browser. diff --git a/Sources/AppAuth/macOS/OIDExternalUserAgentMac.m b/Sources/AppAuth/macOS/OIDExternalUserAgentMac.m index 184767668..edfad58f8 100644 --- a/Sources/AppAuth/macOS/OIDExternalUserAgentMac.m +++ b/Sources/AppAuth/macOS/OIDExternalUserAgentMac.m @@ -47,6 +47,8 @@ @implementation OIDExternalUserAgentMac { #pragma clang diagnostic pop } +@synthesize presentingWindow = _presentingWindow; + - (instancetype)initWithPresentingWindow:(NSWindow *)presentingWindow { self = [super init]; if (self) { From 6bb946ebd66e26c73a3b2f88683d498ae8f570f3 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:40:41 -0700 Subject: [PATCH 2/5] g-orchestrated: share the iOS user agent setup and test the instance presenters --- CHANGELOG.md | 1 + .../AppAuth/iOS/OIDAuthorizationService+IOS.h | 19 ++-- .../AppAuth/iOS/OIDAuthorizationService+IOS.m | 103 ++++++++++-------- .../macOS/OIDAuthorizationService+Mac.h | 16 +-- .../macOS/OIDAuthorizationService+Mac.m | 19 ++-- UnitTests/OIDExternalUserAgentIOSTests.m | 93 ++++++++++++++++ 6 files changed, 185 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa17ca1c2..0fd6bb026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fix a crash (`NSInvalidArgumentException`) when a token, registration or device authorization endpoint answers with a JSON array instead of an object. The callback now gets an error. Addresses issue #987. - Added instance-method counterparts of the `OIDAuthorizationService` class methods, and made `-init` public, so the service can be injected and faked in tests. - Deprecated `OIDAuthorizationService.configuration`. It is never set and is always `nil`; use the request's `configuration` instead. It will be removed in 4.0. +- Added instance-method counterparts of the iOS and macOS `OIDAuthorizationService` convenience methods, and read-only `presentingViewController` / `presentingWindow` properties on the external user agents. # 3.0.0 - BREAKING: Updates made to support Xcode 27. ([#972](https://github.com/openid/AppAuth-iOS/pull/972), [#973](https://github.com/openid/AppAuth-iOS/pull/973)) diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h index 9aeb50517..f04a63329 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h @@ -60,14 +60,16 @@ NS_ASSUME_NONNULL_BEGIN prefersEphemeralSession:(BOOL)prefersEphemeralSession callback:(OIDAuthorizationCallback)callback API_AVAILABLE(ios(13)); -/*! @brief Instance counterpart of @c +presentAuthorizationRequest:presentingViewController:callback:. +/*! @brief Instance counterpart of + @c +presentAuthorizationRequest:presentingViewController:callback:. @param request The authorization request. @param presentingViewController The view controller from which to present authentication UI. @param callback The method called when the request has completed or failed. */ -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingViewController:(UIViewController *)presentingViewController - callback:(OIDAuthorizationCallback)callback; +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + callback:(OIDAuthorizationCallback)callback; /*! @brief Instance counterpart of @c +presentAuthorizationRequest:presentingViewController:prefersEphemeralSession:callback:. @@ -77,10 +79,11 @@ NS_ASSUME_NONNULL_BEGIN session. See @c ASWebAuthenticationSession.prefersEphemeralWebBrowserSession for more. @param callback The method called when the request has completed or failed. */ -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingViewController:(UIViewController *)presentingViewController - prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback API_AVAILABLE(ios(13)); @end diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m index b761516ea..7c81bbda6 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.m @@ -26,64 +26,81 @@ NS_ASSUME_NONNULL_BEGIN -@implementation OIDAuthorizationService (IOS) - -+ (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingViewController:(UIViewController *)presentingViewController - callback:(OIDAuthorizationCallback)callback { - id externalUserAgent; +/*! @brief The platform's external user agent, presenting from @c presentingViewController. + */ +static id OIDExternalUserAgentForViewController( + UIViewController *presentingViewController) { #if TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] + return [[OIDExternalUserAgentCatalyst alloc] initWithPresentingViewController:presentingViewController]; #else // TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:presentingViewController]; + return [[OIDExternalUserAgentIOS alloc] + initWithPresentingViewController:presentingViewController]; #endif // TARGET_OS_MACCATALYST - return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; } -+ (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingViewController:(UIViewController *)presentingViewController - prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback { - id externalUserAgent; +/*! @brief The platform's external user agent, presenting from @c presentingViewController, with + the given ephemeral session preference. + */ +static id OIDEphemeralCapableExternalUserAgentForViewController( + UIViewController *presentingViewController, BOOL prefersEphemeralSession) { #if TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] + return [[OIDExternalUserAgentCatalyst alloc] initWithPresentingViewController:presentingViewController - prefersEphemeralSession:prefersEphemeralSession]; + prefersEphemeralSession:prefersEphemeralSession]; #else // TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:presentingViewController + return [[OIDExternalUserAgentIOS alloc] + initWithPresentingViewController:presentingViewController prefersEphemeralSession:prefersEphemeralSession]; #endif // TARGET_OS_MACCATALYST - return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; } -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingViewController:(UIViewController *)presentingViewController - callback:(OIDAuthorizationCallback)callback { - id externalUserAgent; -#if TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] - initWithPresentingViewController:presentingViewController]; -#else // TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:presentingViewController]; -#endif // TARGET_OS_MACCATALYST - return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; +@implementation OIDAuthorizationService (IOS) + ++ (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + callback:(OIDAuthorizationCallback)callback { + id externalUserAgent = + OIDExternalUserAgentForViewController(presentingViewController); + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; } -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingViewController:(UIViewController *)presentingViewController - prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback { - id externalUserAgent; -#if TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentCatalyst alloc] - initWithPresentingViewController:presentingViewController - prefersEphemeralSession:prefersEphemeralSession]; -#else // TARGET_OS_MACCATALYST - externalUserAgent = [[OIDExternalUserAgentIOS alloc] initWithPresentingViewController:presentingViewController - prefersEphemeralSession:prefersEphemeralSession]; -#endif // TARGET_OS_MACCATALYST - return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; ++ (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { + id externalUserAgent = + OIDEphemeralCapableExternalUserAgentForViewController(presentingViewController, + prefersEphemeralSession); + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + callback:(OIDAuthorizationCallback)callback { + id externalUserAgent = + OIDExternalUserAgentForViewController(presentingViewController); + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; +} + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingViewController:(UIViewController *)presentingViewController + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { + id externalUserAgent = + OIDEphemeralCapableExternalUserAgentForViewController(presentingViewController, + prefersEphemeralSession); + return [self presentAuthorizationRequest:request + externalUserAgent:externalUserAgent + callback:callback]; } @end diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h index 6cab9e9bf..a5a563802 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h @@ -76,9 +76,10 @@ NS_ASSUME_NONNULL_BEGIN @param presentingWindow The window to present the authentication flow. @param callback The method called when the request has completed or failed. */ -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingWindow:(NSWindow *)presentingWindow - callback:(OIDAuthorizationCallback)callback; +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + callback:(OIDAuthorizationCallback)callback; /*! @brief Instance counterpart of @c +presentAuthorizationRequest:presentingWindow:prefersEphemeralSession:callback:. @@ -88,10 +89,11 @@ NS_ASSUME_NONNULL_BEGIN session. See @c ASWebAuthenticationSession.prefersEphemeralWebBrowserSession for more. @param callback The method called when the request has completed or failed. */ -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingWindow:(NSWindow *)presentingWindow - prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback API_AVAILABLE(macos(10.15)); @end diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m index aea3619fc..19763614a 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.m @@ -57,19 +57,22 @@ @implementation OIDAuthorizationService (Mac) callback:callback]; } -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingWindow:(NSWindow *)presentingWindow - callback:(OIDAuthorizationCallback)callback { - OIDExternalUserAgentMac *externalUserAgent = [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow]; +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + callback:(OIDAuthorizationCallback)callback { + OIDExternalUserAgentMac *externalUserAgent = + [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow]; return [self presentAuthorizationRequest:request externalUserAgent:externalUserAgent callback:callback]; } -- (id)presentAuthorizationRequest:(OIDAuthorizationRequest *)request - presentingWindow:(NSWindow *)presentingWindow - prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback { +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + presentingWindow:(NSWindow *)presentingWindow + prefersEphemeralSession:(BOOL)prefersEphemeralSession + callback:(OIDAuthorizationCallback)callback { OIDExternalUserAgentMac *externalUserAgent = [[OIDExternalUserAgentMac alloc] initWithPresentingWindow:presentingWindow prefersEphemeralSession:prefersEphemeralSession]; diff --git a/UnitTests/OIDExternalUserAgentIOSTests.m b/UnitTests/OIDExternalUserAgentIOSTests.m index 7cc7fd8c6..f8861bf35 100644 --- a/UnitTests/OIDExternalUserAgentIOSTests.m +++ b/UnitTests/OIDExternalUserAgentIOSTests.m @@ -26,10 +26,13 @@ #import +#import "Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h" #import "Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h" #import "Sources/AppAuthCore/OIDAuthorizationRequest.h" +#import "Sources/AppAuthCore/OIDAuthorizationService.h" #import "Sources/AppAuthCore/OIDEndSessionRequest.h" #import "Sources/AppAuthCore/OIDExternalUserAgentRequest.h" +#import "Sources/AppAuthCore/OIDExternalUserAgentSession.h" #import "Sources/AppAuthCore/OIDResponseTypes.h" #import "Sources/AppAuthCore/OIDScopes.h" #import "Sources/AppAuthCore/OIDServiceConfiguration.h" @@ -78,6 +81,51 @@ - (NSString *)redirectScheme { @end +/*! @brief An external user agent that refuses to present anything. + */ +@interface OIDRefusingExternalUserAgent : NSObject +@end + +@implementation OIDRefusingExternalUserAgent + +- (BOOL)presentExternalUserAgentRequest:(id)request + session:(id)session { + return NO; +} + +- (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(void))completion { + if (completion) { + completion(); + } +} + +@end + +/*! @brief Records the external user agent it is handed, then fails the flow with a user agent + that refuses to present. + */ +@interface OIDUserAgentRecordingAuthorizationService : OIDAuthorizationService + +/*! @brief The external user agent passed to the most recent authorization request. + */ +@property(nonatomic, readonly, nullable) id lastExternalUserAgent; + +@end + +@implementation OIDUserAgentRecordingAuthorizationService + +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDAuthorizationCallback)callback { + _lastExternalUserAgent = externalUserAgent; + return [super presentAuthorizationRequest:request + externalUserAgent:[[OIDRefusingExternalUserAgent alloc] init] + callback:callback]; +} + +@end + /*! @brief Unit tests for the iOS external user agent's HTTPS redirect callback support. */ @interface OIDExternalUserAgentIOSTests : XCTestCase @@ -189,6 +237,51 @@ - (void)testNoHTTPSCallbackForUnsupportedRequestType { } } +/*! @brief The presenting view controller reads back as the one passed to the initializer. + */ +- (void)testPresentingViewControllerIsTheOneItWasCreatedWith { + UIViewController *presentingViewController = [[UIViewController alloc] init]; + OIDExternalUserAgentIOS *userAgent = [[OIDExternalUserAgentIOS alloc] + initWithPresentingViewController:presentingViewController]; + XCTAssertEqual(userAgent.presentingViewController, presentingViewController); +} + +/*! @brief The instance convenience method hands an iOS user agent for the given view controller to + the instance core method. + */ +- (void)testInstancePresentAuthorizationRequestBuildsIOSUserAgent { + OIDUserAgentRecordingAuthorizationService *service = + [[OIDUserAgentRecordingAuthorizationService alloc] init]; + UIViewController *presentingViewController = [[UIViewController alloc] init]; + OIDAuthorizationRequest *request = [self authorizationRequestWithRedirectURL: + [NSURL URLWithString:@"com.example.app:/oauth2redirect"]]; + [service presentAuthorizationRequest:request + presentingViewController:presentingViewController + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) {}]; + XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); + OIDExternalUserAgentIOS *userAgent = (OIDExternalUserAgentIOS *)service.lastExternalUserAgent; + XCTAssertEqual(userAgent.presentingViewController, presentingViewController); +} + +/*! @brief The ephemeral instance convenience method does the same. + */ +- (void)testInstancePresentAuthorizationRequestWithEphemeralSessionBuildsIOSUserAgent { + OIDUserAgentRecordingAuthorizationService *service = + [[OIDUserAgentRecordingAuthorizationService alloc] init]; + UIViewController *presentingViewController = [[UIViewController alloc] init]; + OIDAuthorizationRequest *request = [self authorizationRequestWithRedirectURL: + [NSURL URLWithString:@"com.example.app:/oauth2redirect"]]; + [service presentAuthorizationRequest:request + presentingViewController:presentingViewController + prefersEphemeralSession:YES + callback:^(OIDAuthorizationResponse *_Nullable response, + NSError *_Nullable error) {}]; + XCTAssertTrue([service.lastExternalUserAgent isKindOfClass:[OIDExternalUserAgentIOS class]]); + OIDExternalUserAgentIOS *userAgent = (OIDExternalUserAgentIOS *)service.lastExternalUserAgent; + XCTAssertEqual(userAgent.presentingViewController, presentingViewController); +} + @end #pragma GCC diagnostic pop From e718d48c48ba7bd8d790a9afbff53a7fa5f7a32c Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:44:04 -0700 Subject: [PATCH 3/5] g-orchestrated: give the iOS test user agent its own name --- UnitTests/OIDExternalUserAgentIOSTests.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitTests/OIDExternalUserAgentIOSTests.m b/UnitTests/OIDExternalUserAgentIOSTests.m index f8861bf35..e01a80080 100644 --- a/UnitTests/OIDExternalUserAgentIOSTests.m +++ b/UnitTests/OIDExternalUserAgentIOSTests.m @@ -83,10 +83,10 @@ - (NSString *)redirectScheme { /*! @brief An external user agent that refuses to present anything. */ -@interface OIDRefusingExternalUserAgent : NSObject +@interface OIDRefusingIOSTestUserAgent : NSObject @end -@implementation OIDRefusingExternalUserAgent +@implementation OIDRefusingIOSTestUserAgent - (BOOL)presentExternalUserAgentRequest:(id)request session:(id)session { @@ -120,7 +120,7 @@ @implementation OIDUserAgentRecordingAuthorizationService callback:(OIDAuthorizationCallback)callback { _lastExternalUserAgent = externalUserAgent; return [super presentAuthorizationRequest:request - externalUserAgent:[[OIDRefusingExternalUserAgent alloc] init] + externalUserAgent:[[OIDRefusingIOSTestUserAgent alloc] init] callback:callback]; } From 48388491168bd4a9bab8ced8cd4a9da91901d99b Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:56:39 -0700 Subject: [PATCH 4/5] g-orchestrated: link the iOS static library tests with -ObjC --- AppAuth.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AppAuth.xcodeproj/project.pbxproj b/AppAuth.xcodeproj/project.pbxproj index 1c61157b5..02a940914 100644 --- a/AppAuth.xcodeproj/project.pbxproj +++ b/AppAuth.xcodeproj/project.pbxproj @@ -2959,6 +2959,7 @@ INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + OTHER_LDFLAGS = "-ObjC"; PRODUCT_BUNDLE_IDENTIFIER = net.openid.appauth.AppAuthTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "UnitTests/OIDAppAuthTests-Bridging-Header.h"; @@ -2976,6 +2977,7 @@ INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + OTHER_LDFLAGS = "-ObjC"; PRODUCT_BUNDLE_IDENTIFIER = net.openid.appauth.AppAuthTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "UnitTests/OIDAppAuthTests-Bridging-Header.h"; From d7af094551e0338e4855ca3d885402feef4bcb66 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Wed, 11 Nov 2026 14:22:09 -0800 Subject: [PATCH 5/5] g-orchestrated: drop the redundant availability on the new instance methods --- Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h | 3 +-- Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h index f04a63329..86ae01988 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h @@ -83,8 +83,7 @@ NS_ASSUME_NONNULL_BEGIN presentAuthorizationRequest:(OIDAuthorizationRequest *)request presentingViewController:(UIViewController *)presentingViewController prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback - API_AVAILABLE(ios(13)); + callback:(OIDAuthorizationCallback)callback; @end diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h index a5a563802..973e5f8e0 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h @@ -93,8 +93,7 @@ NS_ASSUME_NONNULL_BEGIN presentAuthorizationRequest:(OIDAuthorizationRequest *)request presentingWindow:(NSWindow *)presentingWindow prefersEphemeralSession:(BOOL)prefersEphemeralSession - callback:(OIDAuthorizationCallback)callback - API_AVAILABLE(macos(10.15)); + callback:(OIDAuthorizationCallback)callback; @end