Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
64 changes: 38 additions & 26 deletions Sources/AppAuth/iOS/OIDAuthorizationService+IOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,46 @@

NS_ASSUME_NONNULL_BEGIN

/*! @brief The iOS convenience instance methods of @c OIDAuthorizationService.
*/
@protocol OIDAuthorizationServiceIOSProtocol <OIDAuthorizationServiceProtocol>

/*! @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<OIDExternalUserAgentSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
presentingViewController:(UIViewController *)presentingViewController
callback:(OIDAuthorizationCallback)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<OIDExternalUserAgentSession>)
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) <OIDAuthorizationServiceIOSProtocol>

/*! @brief Perform an authorization flow, presenting an appropriate browser for the user to
authenticate.
Expand Down Expand Up @@ -60,31 +97,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<OIDExternalUserAgentSession>)
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<OIDExternalUserAgentSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
presentingViewController:(UIViewController *)presentingViewController
prefersEphemeralSession:(BOOL)prefersEphemeralSession
callback:(OIDAuthorizationCallback)callback;

@end

NS_ASSUME_NONNULL_END
Expand Down
62 changes: 37 additions & 25 deletions Sources/AppAuth/macOS/OIDAuthorizationService+Mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,45 @@

NS_ASSUME_NONNULL_BEGIN

/*! @brief The macOS convenience instance methods of @c OIDAuthorizationService.
*/
@protocol OIDAuthorizationServiceMacProtocol <OIDAuthorizationServiceProtocol>

/*! @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<OIDExternalUserAgentSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
presentingWindow:(NSWindow *)presentingWindow
callback:(OIDAuthorizationCallback)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<OIDExternalUserAgentSession>)
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) <OIDAuthorizationServiceMacProtocol>

/*! @brief Perform an authorization flow.
@param request The authorization request.
Expand Down Expand Up @@ -71,30 +107,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<OIDExternalUserAgentSession>)
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<OIDExternalUserAgentSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
presentingWindow:(NSWindow *)presentingWindow
prefersEphemeralSession:(BOOL)prefersEphemeralSession
callback:(OIDAuthorizationCallback)callback;

@end

NS_ASSUME_NONNULL_END
Expand Down
107 changes: 62 additions & 45 deletions Sources/AppAuthCore/OIDAuthorizationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,69 @@ typedef NSDictionary<NSString *, NSString *> *_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<OIDAuthorizationServiceProtocol> can be handed a fake in
tests. @c OIDAuthorizationService conforms, and its instance methods call the matching
class methods.
*/
@protocol OIDAuthorizationServiceProtocol <NSObject>

/*! @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<OIDExternalUserAgentSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
externalUserAgent:(id<OIDExternalUserAgent>)externalUserAgent
callback:(OIDAuthorizationCallback)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<OIDExternalUserAgentSession>)
presentEndSessionRequest:(OIDEndSessionRequest *)request
externalUserAgent:(id<OIDExternalUserAgent>)externalUserAgent
callback:(OIDEndSessionCallback)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 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.
*/
- (void)performTokenRequest:(OIDTokenRequest *)request
originalAuthorizationResponse:(OIDAuthorizationResponse *_Nullable)authorizationResponse
callback:(OIDTokenCallback)callback;

/*! @brief Performs a registration request.
@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 <OIDAuthorizationServiceProtocol>

/*! @brief Unused, and always nil.
@discussion No initializer sets this, and nothing in AppAuth reads it. Each request carries
Expand All @@ -91,7 +150,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;

Expand Down Expand Up @@ -165,49 +225,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<OIDExternalUserAgentSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
externalUserAgent:(id<OIDExternalUserAgent>)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<OIDExternalUserAgentSession>)
presentEndSessionRequest:(OIDEndSessionRequest *)request
externalUserAgent:(id<OIDExternalUserAgent>)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
8 changes: 8 additions & 0 deletions UnitTests/OIDAuthorizationServiceInstanceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<OIDAuthorizationServiceProtocol> 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];
Expand Down
Loading