diff --git a/Source/OIDServiceDiscovery.m b/Source/OIDServiceDiscovery.m index ca81108a8..13565e35d 100644 --- a/Source/OIDServiceDiscovery.m +++ b/Source/OIDServiceDiscovery.m @@ -23,6 +23,10 @@ NS_ASSUME_NONNULL_BEGIN +/*! @brief The key for the @c discoveryDictionary property. + */ +static NSString *const kDiscoveryDictionaryKey = @"discoveryDictionary"; + /*! Field keys associated with an OpenID Connect Discovery Document. */ static NSString *const kIssuerKey = @"issuer"; static NSString *const kAuthorizationEndpointKey = @"authorization_endpoint"; @@ -191,7 +195,12 @@ + (BOOL)supportsSecureCoding { - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { NSError *error; - NSDictionary *dictionary = [[NSDictionary alloc] initWithCoder:aDecoder]; + NSDictionary *dictionary = nil; + if (@available(iOS 11.0, macCatalyst 13, macOS 10.13, tvOS 11, watchOS 4, *)) { + dictionary = [aDecoder decodeObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSArray class], nil] forKey:kDiscoveryDictionaryKey]; + } else { + dictionary = [[NSDictionary alloc] initWithCoder:aDecoder]; + } self = [self initWithDictionary:dictionary error:&error]; if (error) { return nil; @@ -200,7 +209,11 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { } - (void)encodeWithCoder:(NSCoder *)aCoder { - [_discoveryDictionary encodeWithCoder:aCoder]; + if (@available(iOS 11.0, macCatalyst 13, macOS 10.13, tvOS 11, watchOS 4, *)) { + [aCoder encodeObject:_discoveryDictionary forKey:kDiscoveryDictionaryKey]; + } else { + [_discoveryDictionary encodeWithCoder:aCoder]; + } } #pragma mark - Properties diff --git a/UnitTests/OIDServiceDiscoveryTests.m b/UnitTests/OIDServiceDiscoveryTests.m index b9a13ce86..27f26aa8c 100644 --- a/UnitTests/OIDServiceDiscoveryTests.m +++ b/UnitTests/OIDServiceDiscoveryTests.m @@ -128,7 +128,7 @@ + (NSDictionary *)completeServiceDiscoveryDictionary { kTokenEndpointAuthSigningAlgorithmValuesSupportedKey : @"Token Endpoint Auth Signing Algorithm Values Supported", kDisplayValuesSupportedKey : @"Display Values Supported", - kClaimTypesSupportedKey : @"Claim Types Supported", + kClaimTypesSupportedKey : @[@"normal"], kClaimsSupportedKey : @"Claims Supported", kServiceDocumentationKey : @"Service Documentation", kClaimsLocalesSupportedKey : @"Claims Locales Supported", @@ -398,6 +398,12 @@ - (void)testSecureCoding { OIDServiceDiscovery *unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data]; XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @""); + + if (@available(iOS 11.0, macCatalyst 13, macOS 10.13, tvOS 11, watchOS 4, *)) { + data = [NSKeyedArchiver archivedDataWithRootObject:discovery requiringSecureCoding:YES error:&error]; + unarchived = [NSKeyedUnarchiver unarchivedObjectOfClass:[OIDServiceDiscovery class] fromData:data error:&error]; + XCTAssertEqualObjects(discovery.discoveryDictionary, unarchived.discoveryDictionary, @""); + } } /*! @brief Tests the NSCopying implementation by round-tripping an instance through the copying