Skip to content
Closed
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
17 changes: 15 additions & 2 deletions Source/OIDServiceDiscovery.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion UnitTests/OIDServiceDiscoveryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the build for older versions of other platforms where the NSKeyedArchiver/NSKeyedUnarchiver are not available.

Need more platform checks:

if (@available(iOS 11, macCatalyst 13, macOS 10.13, tvOS 11, *)) {
  ...
}

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
Expand Down