Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit c077eb7

Browse files
authored
Allow customizing the ID Token validator (#8)
These changes allow users of the SDK to override the ID Token Validator with a custom implementation without introducing breaking changes into the API.
1 parent 7587304 commit c077eb7

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Source/AppAuthCore/OIDAuthorizationService.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@class OIDAuthorizationResponse;
2424
@class OIDEndSessionRequest;
2525
@class OIDEndSessionResponse;
26+
@class OIDIDTokenValidator;
2627
@class OIDRegistrationRequest;
2728
@class OIDRegistrationResponse;
2829
@class OIDServiceConfiguration;
@@ -90,6 +91,12 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg
9091
*/
9192
@property(nonatomic, readonly) OIDServiceConfiguration *configuration;
9293

94+
/*! @brief The ID Token's validator instance used in the `performTokenRequest` methods.
95+
@remarks Upon initialization the default validator (`[OIDIDTokenValidator new]`) is used.
96+
When an empty validator is set, the ID Token validation will be skipped.
97+
*/
98+
@property(nonatomic, class, nullable) OIDIDTokenValidator *idTokenValidator;
99+
93100
/*! @internal
94101
@brief Unavailable. This class should not be initialized.
95102
*/

Source/AppAuthCore/OIDAuthorizationService.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,22 @@ - (void)didFinishWithResponse:(nullable OIDEndSessionResponse *)response
311311

312312
@implementation OIDAuthorizationService
313313

314+
static OIDIDTokenValidator *_idTokenValidator;
315+
316+
+ (void)initialize {
317+
[super initialize];
318+
319+
_idTokenValidator = [OIDIDTokenValidator new];
320+
}
321+
322+
+ (nullable OIDIDTokenValidator *)idTokenValidator {
323+
return _idTokenValidator;
324+
}
325+
326+
+ (void)setIdTokenValidator:(nullable OIDIDTokenValidator *)idTokenValidator {
327+
_idTokenValidator = idTokenValidator;
328+
}
329+
314330
+ (void)discoverServiceConfigurationForIssuer:(NSURL *)issuerURL
315331
completion:(OIDDiscoveryCallback)completion {
316332
NSURL *fullDiscoveryURL =
@@ -532,9 +548,9 @@ + (void)performTokenRequest:(OIDTokenRequest *)request
532548
}
533549

534550
// If an ID Token is included in the response, validates the ID Token.
535-
if (tokenResponse.idToken) {
536-
NSError *idTokenValidationError = [[OIDIDTokenValidator new] validateIDTokenFromTokenResponse:tokenResponse
537-
authorizationResponse:authorizationResponse];
551+
if (tokenResponse.idToken && self.idTokenValidator) {
552+
NSError *idTokenValidationError = [self.idTokenValidator validateIDTokenFromTokenResponse:tokenResponse
553+
authorizationResponse:authorizationResponse];
538554
if (idTokenValidationError) {
539555
dispatch_async(dispatch_get_main_queue(), ^{
540556
callback(nil, idTokenValidationError);

0 commit comments

Comments
 (0)