From 25b4d350b08414d83de15215d500e94068f2a8da Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:21:28 -0800 Subject: [PATCH 1/2] g-orchestrated: declare the service's instance methods in protocols --- CHANGELOG.md | 2 +- .../AppAuth/iOS/OIDAuthorizationService+IOS.h | 58 +++++----- .../macOS/OIDAuthorizationService+Mac.h | 56 +++++----- Sources/AppAuthCore/OIDAuthorizationService.h | 100 ++++++++++-------- .../OIDAuthorizationServiceInstanceTests.m | 8 ++ 5 files changed, 127 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fd6bb026..9bce76cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Discovery documents with a JSON `null` or a non-string value in an optional URL-valued field no longer raise `NSInvalidArgumentException`; the property reads as `nil`. The same value in a required URL field now fails with `OIDErrorCodeInvalidDiscoveryDocument`. An `authorization_endpoint` that does not parse now fails the document too, like the other required URL fields. - Deprecated CocoaPods distribution. AppAuth 3.0.0 is the last release published to CocoaPods; CocoaPods trunk becomes read-only on December 2, 2026. See [MIGRATING_FROM_COCOAPODS.md](MIGRATING_FROM_COCOAPODS.md) for moving to Swift Package Manager. Addresses issue #962. - 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. +- Added instance-method counterparts of the `OIDAuthorizationService` class methods, and made `-init` public, so the service can be injected and faked in tests. `OIDAuthorizationServiceProtocol` declares them, and `OIDAuthorizationServiceIOSProtocol` / `OIDAuthorizationServiceMacProtocol` declare the platform convenience methods. - 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. diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h index 86ae01988..5b03abb0d 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h @@ -27,9 +27,40 @@ NS_ASSUME_NONNULL_BEGIN +/*! @brief The iOS convenience instance methods of @c OIDAuthorizationService. + */ +@protocol OIDAuthorizationServiceIOSProtocol + +/*! @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; + +@end + /*! @brief Provides iOS specific authorization request handling. */ -@interface OIDAuthorizationService (IOS) +@interface OIDAuthorizationService (IOS) /*! @brief Perform an authorization flow, presenting an appropriate browser for the user to authenticate. @@ -60,31 +91,6 @@ 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; - @end NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h index 973e5f8e0..68ef0157b 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h @@ -25,9 +25,39 @@ NS_ASSUME_NONNULL_BEGIN +/*! @brief The macOS convenience instance methods of @c OIDAuthorizationService. + */ +@protocol OIDAuthorizationServiceMacProtocol + +/*! @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; + +@end + /*! @brief Provides macOS specific authorization request handling. */ -@interface OIDAuthorizationService (Mac) +@interface OIDAuthorizationService (Mac) /*! @brief Perform an authorization flow. @param request The authorization request. @@ -71,30 +101,6 @@ 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; - @end NS_ASSUME_NONNULL_END diff --git a/Sources/AppAuthCore/OIDAuthorizationService.h b/Sources/AppAuthCore/OIDAuthorizationService.h index 08524d3c0..6bf695d83 100644 --- a/Sources/AppAuthCore/OIDAuthorizationService.h +++ b/Sources/AppAuthCore/OIDAuthorizationService.h @@ -77,10 +77,62 @@ typedef NSDictionary *_Nullable OIDTokenEndpointParamete typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable registrationResponse, NSError *_Nullable error); +/*! @brief The instance methods of @c OIDAuthorizationService. + @discussion Code that takes an @c id can be handed a fake in + tests. @c OIDAuthorizationService conforms, and its instance methods call the matching + class methods. + */ +@protocol OIDAuthorizationServiceProtocol + +/*! @brief Instance counterpart of @c +presentAuthorizationRequest:externalUserAgent:callback:. + @param request The authorization request. + @param externalUserAgent Generic external user-agent that can present an authorization + request. + @param callback The method called when the request has completed or failed. + */ +- (id) + presentAuthorizationRequest:(OIDAuthorizationRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDAuthorizationCallback)callback; + +/*! @brief Instance counterpart of @c +presentEndSessionRequest:externalUserAgent:callback:. + @param request The end-session logout request. + @param externalUserAgent Generic external user-agent that can present user-agent requests. + @param callback The method called when the request has completed or failed. + */ +- (id) + presentEndSessionRequest:(OIDEndSessionRequest *)request + externalUserAgent:(id)externalUserAgent + callback:(OIDEndSessionCallback)callback; + +/*! @brief Instance counterpart of @c +performTokenRequest:callback:. + @param request The token request. + @param callback The method called when the request has completed or failed. + */ +- (void)performTokenRequest:(OIDTokenRequest *)request callback:(OIDTokenCallback)callback; + +/*! @brief Instance counterpart of @c +performTokenRequest:originalAuthorizationResponse:callback:. + @param request The token request. + @param authorizationResponse The original authorization response related to this token request. + @param callback The method called when the request has completed or failed. + */ +- (void)performTokenRequest:(OIDTokenRequest *)request + originalAuthorizationResponse:(OIDAuthorizationResponse *_Nullable)authorizationResponse + callback:(OIDTokenCallback)callback; + +/*! @brief Instance counterpart of @c +performRegistrationRequest:completion:. + @param request The registration request. + @param completion The method called when the request has completed or failed. + */ +- (void)performRegistrationRequest:(OIDRegistrationRequest *)request + completion:(OIDRegistrationCompletion)completion; + +@end + /*! @brief Performs various OAuth and OpenID Connect related calls via the user agent or \NSURLSession. */ -@interface OIDAuthorizationService : NSObject +@interface OIDAuthorizationService : NSObject /*! @brief Unused, and always nil. @discussion No initializer sets this, and nothing in AppAuth reads it. Each request carries @@ -91,7 +143,8 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg __deprecated_msg("Always nil. Use the configuration on the request instead."); /*! @brief Creates a service whose instance methods call the matching class methods. - @discussion Tests can hand in a subclass that fakes the instance methods. + @discussion Tests can hand in a fake that conforms to @c OIDAuthorizationServiceProtocol + instead. */ - (instancetype)init; @@ -165,49 +218,6 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg + (void)performRegistrationRequest:(OIDRegistrationRequest *)request completion:(OIDRegistrationCompletion)completion; -/*! @brief Instance counterpart of @c +presentAuthorizationRequest:externalUserAgent:callback:. - @param request The authorization request. - @param externalUserAgent Generic external user-agent that can present an authorization - request. - @param callback The method called when the request has completed or failed. - */ -- (id) - presentAuthorizationRequest:(OIDAuthorizationRequest *)request - externalUserAgent:(id)externalUserAgent - callback:(OIDAuthorizationCallback)callback; - -/*! @brief Instance counterpart of @c +presentEndSessionRequest:externalUserAgent:callback:. - @param request The end-session logout request. - @param externalUserAgent Generic external user-agent that can present user-agent requests. - @param callback The method called when the request has completed or failed. - */ -- (id) - presentEndSessionRequest:(OIDEndSessionRequest *)request - externalUserAgent:(id)externalUserAgent - callback:(OIDEndSessionCallback)callback; - -/*! @brief Instance counterpart of @c +performTokenRequest:callback:. - @param request The token request. - @param callback The method called when the request has completed or failed. - */ -- (void)performTokenRequest:(OIDTokenRequest *)request callback:(OIDTokenCallback)callback; - -/*! @brief Instance counterpart of @c +performTokenRequest:originalAuthorizationResponse:callback:. - @param request The token request. - @param authorizationResponse The original authorization response related to this token request. - @param callback The method called when the request has completed or failed. - */ -- (void)performTokenRequest:(OIDTokenRequest *)request - originalAuthorizationResponse:(OIDAuthorizationResponse *_Nullable)authorizationResponse - callback:(OIDTokenCallback)callback; - -/*! @brief Instance counterpart of @c +performRegistrationRequest:completion:. - @param request The registration request. - @param completion The method called when the request has completed or failed. - */ -- (void)performRegistrationRequest:(OIDRegistrationRequest *)request - completion:(OIDRegistrationCompletion)completion; - @end NS_ASSUME_NONNULL_END diff --git a/UnitTests/OIDAuthorizationServiceInstanceTests.m b/UnitTests/OIDAuthorizationServiceInstanceTests.m index b00ad3180..3eabe159c 100644 --- a/UnitTests/OIDAuthorizationServiceInstanceTests.m +++ b/UnitTests/OIDAuthorizationServiceInstanceTests.m @@ -97,6 +97,14 @@ @interface OIDAuthorizationServiceInstanceTests : XCTestCase @implementation OIDAuthorizationServiceInstanceTests +/*! @brief The service conforms to @c OIDAuthorizationServiceProtocol, so it can be passed where the + protocol is expected. + */ +- (void)testServiceConformsToProtocol { + id service = [[OIDAuthorizationService alloc] init]; + XCTAssertTrue([service conformsToProtocol:@protocol(OIDAuthorizationServiceProtocol)]); +} + /*! @brief A refused authorization request fails with @c OIDErrorCodeSafariOpenError. */ - (void)testPresentAuthorizationRequestFailsWhenUserAgentRefuses { OIDAuthorizationService *service = [[OIDAuthorizationService alloc] init]; From 2575477b9447fa49518c9e03e6db0adf37e49e49 Mon Sep 17 00:00:00 2001 From: Worthing ~ <115107835+w-goog@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:27:47 -0800 Subject: [PATCH 2/2] g-orchestrated: describe the protocol methods without pointing at the class methods --- .../AppAuth/iOS/OIDAuthorizationService+IOS.h | 14 ++++++++++---- .../AppAuth/macOS/OIDAuthorizationService+Mac.h | 12 +++++++++--- Sources/AppAuthCore/OIDAuthorizationService.h | 17 ++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h index 5b03abb0d..8baf05c24 100644 --- a/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h +++ b/Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h @@ -31,24 +31,30 @@ NS_ASSUME_NONNULL_BEGIN */ @protocol OIDAuthorizationServiceIOSProtocol -/*! @brief Instance counterpart of - @c +presentAuthorizationRequest:presentingViewController:callback:. +/*! @brief Performs an authorization flow, presenting an appropriate browser for the user to + authenticate. @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. + @return A @c OIDExternalUserAgentSession instance which will terminate when it + receives a @c OIDExternalUserAgentSession.cancel message, or after processing a + @c OIDExternalUserAgentSession.resumeExternalUserAgentFlowWithURL:error: message. */ - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request presentingViewController:(UIViewController *)presentingViewController callback:(OIDAuthorizationCallback)callback; -/*! @brief Instance counterpart of - @c +presentAuthorizationRequest:presentingViewController:prefersEphemeralSession:callback:. +/*! @brief Performs an authorization flow using @c ASWebAuthenticationSession, optionally with an + ephemeral browser session that shares no cookies or data with the normal browser session. @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. + @return A @c OIDExternalUserAgentSession instance which will terminate when it + receives a @c OIDExternalUserAgentSession.cancel message, or after processing a + @c OIDExternalUserAgentSession.resumeExternalUserAgentFlowWithURL:error: message. */ - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request diff --git a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h index 68ef0157b..211982ecb 100644 --- a/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h +++ b/Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h @@ -29,23 +29,29 @@ NS_ASSUME_NONNULL_BEGIN */ @protocol OIDAuthorizationServiceMacProtocol -/*! @brief Instance counterpart of @c +presentAuthorizationRequest:presentingWindow:callback:. +/*! @brief Performs an authorization flow using @c ASWebAuthenticationSession. @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. + @return A @c OIDExternalUserAgentSession instance which will terminate when it + receives a @c OIDExternalUserAgentSession.cancel message, or after processing a + @c OIDExternalUserAgentSession.resumeExternalUserAgentFlowWithURL:error: message. */ - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request presentingWindow:(NSWindow *)presentingWindow callback:(OIDAuthorizationCallback)callback; -/*! @brief Instance counterpart of - @c +presentAuthorizationRequest:presentingWindow:prefersEphemeralSession:callback:. +/*! @brief Performs an authorization flow using @c ASWebAuthenticationSession, optionally with an + ephemeral browser session that shares no cookies or data with the normal browser session. @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. + @return A @c OIDExternalUserAgentSession instance which will terminate when it + receives a @c OIDExternalUserAgentSession.cancel message, or after processing a + @c OIDExternalUserAgentSession.resumeExternalUserAgentFlowWithURL:error: message. */ - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request diff --git a/Sources/AppAuthCore/OIDAuthorizationService.h b/Sources/AppAuthCore/OIDAuthorizationService.h index 6bf695d83..9703915cb 100644 --- a/Sources/AppAuthCore/OIDAuthorizationService.h +++ b/Sources/AppAuthCore/OIDAuthorizationService.h @@ -84,34 +84,41 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg */ @protocol OIDAuthorizationServiceProtocol -/*! @brief Instance counterpart of @c +presentAuthorizationRequest:externalUserAgent:callback:. +/*! @brief Performs an authorization flow using a generic flow shim. @param request The authorization request. @param externalUserAgent Generic external user-agent that can present an authorization request. @param callback The method called when the request has completed or failed. + @return A @c OIDExternalUserAgentSession instance which will terminate when it + receives a @c OIDExternalUserAgentSession.cancel message, or after processing a + @c OIDExternalUserAgentSession.resumeExternalUserAgentFlowWithURL:error: message. */ - (id) presentAuthorizationRequest:(OIDAuthorizationRequest *)request externalUserAgent:(id)externalUserAgent callback:(OIDAuthorizationCallback)callback; -/*! @brief Instance counterpart of @c +presentEndSessionRequest:externalUserAgent:callback:. +/*! @brief Performs a logout request. @param request The end-session logout request. @param externalUserAgent Generic external user-agent that can present user-agent requests. @param callback The method called when the request has completed or failed. + @return A @c OIDExternalUserAgentSession instance which will terminate when it + receives a @c OIDExternalUserAgentSession.cancel message, or after processing a + @c OIDExternalUserAgentSession.resumeExternalUserAgentFlowWithURL:error: message. + @see http://openid.net/specs/openid-connect-session-1_0.html#RPLogout */ - (id) presentEndSessionRequest:(OIDEndSessionRequest *)request externalUserAgent:(id)externalUserAgent callback:(OIDEndSessionCallback)callback; -/*! @brief Instance counterpart of @c +performTokenRequest:callback:. +/*! @brief Performs a token request. @param request The token request. @param callback The method called when the request has completed or failed. */ - (void)performTokenRequest:(OIDTokenRequest *)request callback:(OIDTokenCallback)callback; -/*! @brief Instance counterpart of @c +performTokenRequest:originalAuthorizationResponse:callback:. +/*! @brief Performs a token request. @param request The token request. @param authorizationResponse The original authorization response related to this token request. @param callback The method called when the request has completed or failed. @@ -120,7 +127,7 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg originalAuthorizationResponse:(OIDAuthorizationResponse *_Nullable)authorizationResponse callback:(OIDTokenCallback)callback; -/*! @brief Instance counterpart of @c +performRegistrationRequest:completion:. +/*! @brief Performs a registration request. @param request The registration request. @param completion The method called when the request has completed or failed. */