Skip to content

Crash fix - when cancelling an authentication session #917

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions AppAuth.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "AppAuth"
s.version = "2.0.0"
s.version = "1.7.6"
s.summary = "AppAuth for iOS and macOS is a client SDK for communicating with OAuth 2.0 and OpenID Connect providers."

s.description = <<-DESC
Expand Down Expand Up @@ -31,7 +31,7 @@ It follows the OAuth 2.0 for Native Apps best current practice
# classes of AppAuth with tokens on watchOS and tvOS, but currently the
# library won't help you obtain authorization grants on those platforms.

ios_deployment_target = "12.0"
ios_deployment_target = "9.0"
osx_deployment_target = "10.12"
s.ios.deployment_target = ios_deployment_target
s.osx.deployment_target = osx_deployment_target
Expand Down
26 changes: 12 additions & 14 deletions AppAuth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -2873,7 +2873,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
Expand All @@ -2888,7 +2888,6 @@
340E73861C5D819B0076B1F6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -2897,7 +2896,6 @@
340E73871C5D819B0076B1F6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -2909,7 +2907,7 @@
CLANG_ENABLE_MODULES = YES;
HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/";
INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.openid.appauth.AppAuthTests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -2926,7 +2924,7 @@
CLANG_ENABLE_MODULES = YES;
HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/";
INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.openid.appauth.AppAuthTests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -3040,7 +3038,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/CoreFramework/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.openid.AppAuthCore;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3066,7 +3064,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/CoreFramework/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.openid.AppAuthCore;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3091,7 +3089,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Framework/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.openid.AppAuth-iOS";
PRODUCT_NAME = AppAuth;
Expand All @@ -3116,7 +3114,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Framework/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.openid.AppAuth-iOS";
PRODUCT_NAME = AppAuth;
Expand All @@ -3135,7 +3133,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
HEADER_SEARCH_PATHS = .;
INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.openid.AppAuth-iOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3149,7 +3147,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
HEADER_SEARCH_PATHS = .;
INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.openid.AppAuth-iOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -3403,7 +3401,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
HEADER_SEARCH_PATHS = .;
INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.openid.AppAuth-ExtensionTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3417,7 +3415,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
HEADER_SEARCH_PATHS = .;
INFOPLIST_FILE = UnitTests/UnitTestsInfo.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "net.openid.AppAuth-ExtensionTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# 2.0.0
- Raise minimum supported iOS version to iOS 12. ([#918](https://github.com/openid/AppAuth-iOS/pull/918))
- Remove deprecated `[UIApplication openURL:]` method to compile with Xcode 16. ([#911](https://github.com/openid/AppAuth-iOS/pull/911))

# 1.7.6
- Fix OIDExternalUserAgentIOSCustomBrowser on versions iOS 10+ ([#871](https://github.com/openid/AppAuth-iOS/pull/871))
- Update runners in tests.yml to macos-13. ([#886](https://github.com/openid/AppAuth-iOS/pull/886))
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ Hernan Zalazar <[email protected]> https://github.com/hzalaz
Joseph Heenan <[email protected]> https://github.com/jogu
Julien Bodet <[email protected]> https://github.com/julienbodet
Tobias Schröpf <[email protected]> https://github.com/schroepf
Dave MacLachlan <[email protected]> https://github.com/dmaclach
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let package = Package(
name: "AppAuth",
platforms: [
.macOS(.v10_12),
.iOS(.v12),
.iOS(.v9),
.tvOS(.v9),
.watchOS(.v2)
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ For tvOS, AppAuth implements [OAuth 2.0 Device Authorization Grant

#### Supported Versions

AppAuth supports iOS 12 and above.
AppAuth supports iOS 7 and above.

iOS 9+ uses the in-app browser tab pattern
(via `SFSafariViewController`), and falls back to the system browser (mobile
Expand Down
6 changes: 4 additions & 2 deletions Sources/AppAuth/iOS/OIDExternalUserAgentIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ API_UNAVAILABLE(macCatalyst)
/*! @brief The designated initializer.
@param presentingViewController The view controller from which to present the authentication UI.
@discussion The specific authentication UI used depends on the iOS version and accessibility
options. iOS 12+ uses @c ASWebAuthenticationSession (unless Guided Access is on),
otherwise local browser is used.
options. iOS 8 uses the system browser, iOS 9-10 use @c SFSafariViewController, iOS 11 uses
@c SFAuthenticationSession
(unless Guided Access is on which does not work) or uses @c SFSafariViewController, and iOS
12+ uses @c ASWebAuthenticationSession (unless Guided Access is on).
*/
- (nullable instancetype)initWithPresentingViewController:
(UIViewController *)presentingViewController
Expand Down
74 changes: 63 additions & 11 deletions Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ @interface OIDExternalUserAgentIOS ()<SFSafariViewControllerDelegate>
@end
#endif

API_AVAILABLE(ios(12.0))
static ASWebAuthenticationSession *_webAuthenticationVC;

@implementation OIDExternalUserAgentIOS {
UIViewController *_presentingViewController;
BOOL _prefersEphemeralSession;
Expand All @@ -50,7 +53,7 @@ @implementation OIDExternalUserAgentIOS {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
__weak SFSafariViewController *_safariVC;
ASWebAuthenticationSession *_webAuthenticationVC;
SFAuthenticationSession *_authenticationVC;
#pragma clang diagnostic pop
}

Expand Down Expand Up @@ -103,7 +106,7 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
if (!UIAccessibilityIsGuidedAccessEnabled()) {
__weak OIDExternalUserAgentIOS *weakSelf = self;
NSString *redirectScheme = request.redirectScheme;
ASWebAuthenticationSession *authenticationVC =
_webAuthenticationVC =
[[ASWebAuthenticationSession alloc] initWithURL:requestURL
callbackURLScheme:redirectScheme
completionHandler:^(NSURL * _Nullable callbackURL,
Expand All @@ -112,7 +115,6 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
if (!strongSelf) {
return;
}
strongSelf->_webAuthenticationVC = nil;
if (callbackURL) {
[strongSelf->_session resumeExternalUserAgentFlowWithURL:callbackURL];
} else {
Expand All @@ -125,22 +127,66 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
}];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
authenticationVC.presentationContextProvider = self;
authenticationVC.prefersEphemeralWebBrowserSession = _prefersEphemeralSession;
_webAuthenticationVC.presentationContextProvider = self;
_webAuthenticationVC.prefersEphemeralWebBrowserSession = _prefersEphemeralSession;
}
#endif
_webAuthenticationVC = authenticationVC;
openedUserAgent = [_webAuthenticationVC start];
}
}
// iOS 11, use SFAuthenticationSession
if (@available(iOS 11.0, *)) {
// SFAuthenticationSession doesn't work with guided access (rdar://40809553)
if (!openedUserAgent && !UIAccessibilityIsGuidedAccessEnabled()) {
__weak OIDExternalUserAgentIOS *weakSelf = self;
NSString *redirectScheme = request.redirectScheme;
SFAuthenticationSession *authenticationVC =
[[SFAuthenticationSession alloc] initWithURL:requestURL
callbackURLScheme:redirectScheme
completionHandler:^(NSURL * _Nullable callbackURL,
NSError * _Nullable error) {
__strong OIDExternalUserAgentIOS *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
strongSelf->_authenticationVC = nil;
if (callbackURL) {
[strongSelf->_session resumeExternalUserAgentFlowWithURL:callbackURL];
} else {
NSError *safariError =
[OIDErrorUtilities errorWithCode:OIDErrorCodeUserCanceledAuthorizationFlow
underlyingError:error
description:@"User cancelled."];
[strongSelf->_session failExternalUserAgentFlowWithError:safariError];
}
}];
_authenticationVC = authenticationVC;
openedUserAgent = [authenticationVC start];
}
}
// If all else failed use the local browser.
// iOS 9 and 10, use SFSafariViewController
if (@available(iOS 9.0, *)) {
if (!openedUserAgent && _presentingViewController) {
SFSafariViewController *safariVC =
[[SFSafariViewController alloc] initWithURL:requestURL];
safariVC.delegate = self;
_safariVC = safariVC;
[_presentingViewController presentViewController:safariVC animated:YES completion:nil];
openedUserAgent = YES;
}
}
// iOS 8 and earlier, use mobile Safari
if (!openedUserAgent){
[[UIApplication sharedApplication] openURL:requestURL
options:@{}
completionHandler:nil];
openedUserAgent = YES;
openedUserAgent = [[UIApplication sharedApplication] openURL:requestURL];
}

if (!openedUserAgent) {
[self cleanUp];
NSError *safariError = [OIDErrorUtilities errorWithCode:OIDErrorCodeSafariOpenError
underlyingError:nil
description:@"Unable to open Safari."];
[session failExternalUserAgentFlowWithError:safariError];
}
return openedUserAgent;
}

Expand All @@ -154,6 +200,7 @@ - (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(voi
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
SFSafariViewController *safariVC = _safariVC;
SFAuthenticationSession *authenticationVC = _authenticationVC;
ASWebAuthenticationSession *webAuthenticationVC = _webAuthenticationVC;
#pragma clang diagnostic pop

Expand All @@ -163,6 +210,10 @@ - (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(voi
// dismiss the ASWebAuthenticationSession
[webAuthenticationVC cancel];
if (completion) completion();
} else if (authenticationVC) {
// dismiss the SFAuthenticationSession
[authenticationVC cancel];
if (completion) completion();
} else if (safariVC) {
// dismiss the SFSafariViewController
[safariVC dismissViewControllerAnimated:YES completion:completion];
Expand All @@ -175,6 +226,7 @@ - (void)cleanUp {
// The weak references to |_safariVC| and |_session| are set to nil to avoid accidentally using
// them while not in an authorization flow.
_safariVC = nil;
_authenticationVC = nil;
_webAuthenticationVC = nil;
_session = nil;
_externalUserAgentFlowInProgress = NO;
Expand Down
17 changes: 13 additions & 4 deletions Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,26 @@ - (BOOL)presentExternalUserAgentRequest:(nonnull id<OIDExternalUserAgentRequest>
NSString *testURLString = [NSString stringWithFormat:@"%@://example.com", _canOpenURLScheme];
NSURL *testURL = [NSURL URLWithString:testURLString];
if (![[UIApplication sharedApplication] canOpenURL:testURL]) {
[[UIApplication sharedApplication] openURL:_appStoreURL options:@{} completionHandler:nil];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:_appStoreURL options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:_appStoreURL];
}
return NO;
}
}

// Transforms the request URL and opens it.
NSURL *requestURL = [request externalUserAgentRequestURL];
requestURL = _URLTransformation(requestURL);
BOOL willOpen = [[UIApplication sharedApplication] canOpenURL:requestURL];
[[UIApplication sharedApplication] openURL:requestURL options:@{} completionHandler:nil];
return willOpen;
if (@available(iOS 10.0, *)) {
BOOL willOpen = [[UIApplication sharedApplication] canOpenURL:requestURL];
[[UIApplication sharedApplication] openURL:requestURL options:@{} completionHandler:nil];
return willOpen;
} else {
BOOL openedInBrowser = [[UIApplication sharedApplication] openURL:requestURL];
return openedInBrowser;
}
}

- (void)dismissExternalUserAgentAnimated:(BOOL)animated
Expand Down
15 changes: 6 additions & 9 deletions Sources/AppAuthCore/OIDRegistrationRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,12 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
forKey:kConfigurationKey];
NSString *initialAccessToken = [aDecoder decodeObjectOfClass:[NSString class]
forKey:kInitialAccessToken];
NSArray<NSURL *> *redirectURIs =
[aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [NSURL class]]]
forKey:kRedirectURIsKey];
NSArray<NSString *> *responseTypes =
[aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [NSString class]]]
forKey:kResponseTypesKey];
NSArray<NSString *> *grantTypes =
[aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [NSString class]]]
forKey:kGrantTypesKey];
NSArray<NSURL *> *redirectURIs = [aDecoder decodeObjectOfClass:[NSArray<NSURL *> class]
forKey:kRedirectURIsKey];
NSArray<NSString *> *responseTypes = [aDecoder decodeObjectOfClass:[NSArray<NSString *> class]
forKey:kResponseTypesKey];
NSArray<NSString *> *grantTypes = [aDecoder decodeObjectOfClass:[NSArray<NSString *> class]
forKey:kGrantTypesKey];
NSString *subjectType = [aDecoder decodeObjectOfClass:[NSString class]
forKey:kSubjectTypeKey];
NSString *tokenEndpointAuthenticationMethod =
Expand Down
Loading