From 9a448946b4e2196466c2dbc6e1ddf83dd1eac2b8 Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Wed, 27 Nov 2024 14:51:51 -0800 Subject: [PATCH 1/2] Fix warnings --- Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m | 10 +++++++++- .../iOS/OIDExternalUserAgentIOSCustomBrowser.m | 6 ++++++ Sources/AppAuth/macOS/OIDRedirectHTTPHandler.h | 2 +- Sources/AppAuth/macOS/OIDRedirectHTTPHandler.m | 2 +- Sources/AppAuthCore/OIDAuthState.h | 2 +- Sources/AppAuthCore/OIDRegistrationRequest.h | 4 ++-- Sources/AppAuthCore/OIDRegistrationRequest.m | 2 +- Sources/AppAuthCore/OIDServiceDiscovery.m | 16 ++++++++++------ 8 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m index 4a8cda0a3..3c18fb877 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m @@ -49,6 +49,7 @@ @implementation OIDExternalUserAgentIOS { __weak id _session; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpartial-availability" +#pragma clang diagnostic ignored "-Wdeprecated-declarations" __weak SFSafariViewController *_safariVC; SFAuthenticationSession *_authenticationVC; ASWebAuthenticationSession *_webAuthenticationVC; @@ -140,11 +141,14 @@ - (BOOL)presentExternalUserAgentRequest:(id)request if (!openedUserAgent && !UIAccessibilityIsGuidedAccessEnabled()) { __weak OIDExternalUserAgentIOS *weakSelf = self; NSString *redirectScheme = request.redirectScheme; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" SFAuthenticationSession *authenticationVC = [[SFAuthenticationSession alloc] initWithURL:requestURL callbackURLScheme:redirectScheme completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) { +#pragma clang diagnostic pop __strong OIDExternalUserAgentIOS *strongSelf = weakSelf; if (!strongSelf) { return; @@ -176,8 +180,11 @@ - (BOOL)presentExternalUserAgentRequest:(id)request } } // iOS 8 and earlier, use mobile Safari - if (!openedUserAgent){ + if (!openedUserAgent) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" openedUserAgent = [[UIApplication sharedApplication] openURL:requestURL]; +#pragma clang diagnostic pop } if (!openedUserAgent) { @@ -199,6 +206,7 @@ - (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(voi #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpartial-availability" +#pragma clang diagnostic ignored "-Wdeprecated-declarations" SFSafariViewController *safariVC = _safariVC; SFAuthenticationSession *authenticationVC = _authenticationVC; ASWebAuthenticationSession *webAuthenticationVC = _webAuthenticationVC; diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m b/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m index c49cbbf9c..b9174133c 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentIOSCustomBrowser.m @@ -148,7 +148,10 @@ - (BOOL)presentExternalUserAgentRequest:(nonnull id if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:_appStoreURL options:@{} completionHandler:nil]; } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [[UIApplication sharedApplication] openURL:_appStoreURL]; +#pragma clang diagnostic pop } return NO; } @@ -162,8 +165,11 @@ - (BOOL)presentExternalUserAgentRequest:(nonnull id [[UIApplication sharedApplication] openURL:requestURL options:@{} completionHandler:nil]; return willOpen; } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" BOOL openedInBrowser = [[UIApplication sharedApplication] openURL:requestURL]; return openedInBrowser; +#pragma clang diagnostic pop } } diff --git a/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.h b/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.h index 831eb0bb3..659f55c28 100644 --- a/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.h +++ b/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.h @@ -60,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN Calling this more than once will result in the previous listener being cancelled (equivalent of @c cancelHTTPListener being called). */ -- (NSURL *)startHTTPListener:(NSError **)returnError withPort:(uint16_t)port; +- (nullable NSURL *)startHTTPListener:(NSError **)returnError withPort:(uint16_t)port; /*! @brief Starts listening on the loopback interface on a random available port, and returns a URL with the base address. Use the returned redirect URI to build a @c OIDExternalUserAgentRequest, diff --git a/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.m b/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.m index 3d0d765d8..d73796886 100644 --- a/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.m +++ b/Sources/AppAuth/macOS/OIDRedirectHTTPHandler.m @@ -68,7 +68,7 @@ - (instancetype)initWithSuccessURL:(nullable NSURL *)successURL { return self; } -- (NSURL *)startHTTPListener:(NSError **)returnError withPort:(uint16_t)port { +- (nullable NSURL *)startHTTPListener:(NSError **)returnError withPort:(uint16_t)port { // Cancels any pending requests. [self cancelHTTPListener]; diff --git a/Sources/AppAuthCore/OIDAuthState.h b/Sources/AppAuthCore/OIDAuthState.h index 46c78a831..935fe51d8 100644 --- a/Sources/AppAuthCore/OIDAuthState.h +++ b/Sources/AppAuthCore/OIDAuthState.h @@ -77,7 +77,7 @@ static NSString *const kRefreshTokenRequestException = /*! @brief The most recent authorization response used to update the authorization state. For the implicit flow, this will contain the latest access token. */ -@property(nonatomic, readonly) OIDAuthorizationResponse *lastAuthorizationResponse; +@property(nonatomic, readonly, nullable) OIDAuthorizationResponse *lastAuthorizationResponse; /*! @brief The most recent token response used to update this authorization state. This will contain the latest access token. diff --git a/Sources/AppAuthCore/OIDRegistrationRequest.h b/Sources/AppAuthCore/OIDRegistrationRequest.h index e509c60a2..0548616e0 100644 --- a/Sources/AppAuthCore/OIDRegistrationRequest.h +++ b/Sources/AppAuthCore/OIDRegistrationRequest.h @@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN @see Section 3 of OpenID Connect Dynamic Client Registration 1.0 https://openid.net/specs/openid-connect-registration-1_0.html#ClientRegistration */ -@property(nonatomic, readonly) NSString *initialAccessToken; +@property(nonatomic, readonly, nullable) NSString *initialAccessToken; /*! @brief The application type to register, will always be 'native'. @remarks application_type @@ -134,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN /*! @brief Constructs an @c NSURLRequest representing the registration request. @return An @c NSURLRequest representing the registration request. */ -- (NSURLRequest *)URLRequest; +- (nullable NSURLRequest *)URLRequest; @end diff --git a/Sources/AppAuthCore/OIDRegistrationRequest.m b/Sources/AppAuthCore/OIDRegistrationRequest.m index 9efd18fdd..0fc85d198 100644 --- a/Sources/AppAuthCore/OIDRegistrationRequest.m +++ b/Sources/AppAuthCore/OIDRegistrationRequest.m @@ -182,7 +182,7 @@ - (NSString *)description { requestBody]; } -- (NSURLRequest *)URLRequest { +- (nullable NSURLRequest *)URLRequest { static NSString *const kHTTPPost = @"POST"; static NSString *const kBearer = @"Bearer"; static NSString *const kHTTPContentTypeHeaderKey = @"Content-Type"; diff --git a/Sources/AppAuthCore/OIDServiceDiscovery.m b/Sources/AppAuthCore/OIDServiceDiscovery.m index 4d96f9db3..d35cbf2dc 100644 --- a/Sources/AppAuthCore/OIDServiceDiscovery.m +++ b/Sources/AppAuthCore/OIDServiceDiscovery.m @@ -94,15 +94,19 @@ - (nullable instancetype)initWithJSONData:(NSData *)serviceDiscoveryJSONData NSDictionary *json = [NSJSONSerialization JSONObjectWithData:serviceDiscoveryJSONData options:0 error:&jsonError]; if (!json || jsonError) { - *error = [OIDErrorUtilities errorWithCode:OIDErrorCodeJSONDeserializationError - underlyingError:jsonError - description:jsonError.localizedDescription]; + if (error) { + *error = [OIDErrorUtilities errorWithCode:OIDErrorCodeJSONDeserializationError + underlyingError:jsonError + description:jsonError.localizedDescription]; + } return nil; } if (![json isKindOfClass:[NSDictionary class]]) { - *error = [OIDErrorUtilities errorWithCode:OIDErrorCodeInvalidDiscoveryDocument - underlyingError:nil - description:@"Discovery document isn't a dictionary"]; + if (error) { + *error = [OIDErrorUtilities errorWithCode:OIDErrorCodeInvalidDiscoveryDocument + underlyingError:nil + description:@"Discovery document isn't a dictionary"]; + } return nil; } From 86392d468e9ef5b730c7fbfb81ab328375f67e7a Mon Sep 17 00:00:00 2001 From: Loic Sharma Date: Mon, 2 Dec 2024 11:21:19 -0800 Subject: [PATCH 2/2] Move block out of clang diagnostic ignore --- Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m index 3c18fb877..5d0908a00 100644 --- a/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m +++ b/Sources/AppAuth/iOS/OIDExternalUserAgentIOS.m @@ -141,29 +141,31 @@ - (BOOL)presentExternalUserAgentRequest:(id)request if (!openedUserAgent && !UIAccessibilityIsGuidedAccessEnabled()) { __weak OIDExternalUserAgentIOS *weakSelf = self; NSString *redirectScheme = request.redirectScheme; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - SFAuthenticationSession *authenticationVC = - [[SFAuthenticationSession alloc] initWithURL:requestURL - callbackURLScheme:redirectScheme - completionHandler:^(NSURL * _Nullable callbackURL, - NSError * _Nullable error) { -#pragma clang diagnostic pop + SFAuthenticationCompletionHandler completionHandler = ^(NSURL * _Nullable callbackURL, + NSError * _Nullable error) { __strong OIDExternalUserAgentIOS *strongSelf = weakSelf; if (!strongSelf) { - return; + 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]; + [OIDErrorUtilities errorWithCode:OIDErrorCodeUserCanceledAuthorizationFlow + underlyingError:error + description:@"User cancelled."]; + [strongSelf->_session failExternalUserAgentFlowWithError:safariError]; } - }]; + }; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + SFAuthenticationSession *authenticationVC = + [[SFAuthenticationSession alloc] initWithURL:requestURL + callbackURLScheme:redirectScheme + completionHandler:completionHandler]; +#pragma clang diagnostic pop _authenticationVC = authenticationVC; openedUserAgent = [authenticationVC start]; }