@@ -35,7 +35,7 @@ - (dispatch_queue_t)methodQueue
35
35
static NSUInteger const kCodeVerifierBytes = 32 ;
36
36
37
37
RCT_EXPORT_MODULE ()
38
-
38
+
39
39
RCT_REMAP_METHOD(register ,
40
40
issuer: (NSString *) issuer
41
41
redirectUrls: (NSArray *) redirectUrls
@@ -221,7 +221,7 @@ + (nullable NSString *)codeChallengeS256ForVerifier:(NSString *)codeVerifier {
221
221
return [OIDTokenUtilities encodeBase64urlNoPadding: sha256Verifier];
222
222
}
223
223
224
-
224
+
225
225
/*
226
226
* Perform dynamic client registration with provided OIDServiceConfiguration
227
227
*/
@@ -239,7 +239,7 @@ - (void)registerWithConfiguration: (OIDServiceConfiguration *) configuration
239
239
for (NSString *urlString in redirectUrlStrings) {
240
240
[redirectUrls addObject: [NSURL URLWithString: urlString]];
241
241
}
242
-
242
+
243
243
OIDRegistrationRequest *request =
244
244
[[OIDRegistrationRequest alloc ] initWithConfiguration: configuration
245
245
redirectURIs: redirectUrls
@@ -248,19 +248,19 @@ - (void)registerWithConfiguration: (OIDServiceConfiguration *) configuration
248
248
subjectType: subjectType
249
249
tokenEndpointAuthMethod: tokenEndpointAuthMethod
250
250
additionalParameters: additionalParameters];
251
-
251
+
252
252
[OIDAuthorizationService performRegistrationRequest: request
253
253
completion: ^(OIDRegistrationResponse *_Nullable response,
254
254
NSError *_Nullable error) {
255
255
if (response) {
256
256
resolve ([self formatRegistrationResponse: response]);
257
257
} else {
258
258
reject ([self getErrorCode: error defaultCode: @" registration_failed" ],
259
- [error localizedDescription ], error);
259
+ [self getErrorMessage: error ], error);
260
260
}
261
261
}];
262
262
}
263
-
263
+
264
264
/*
265
265
* Authorize a user in exchange for a token with provided OIDServiceConfiguration
266
266
*/
@@ -324,7 +324,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
324
324
resolve ([self formatAuthorizationResponse: authorizationResponse withCodeVerifier: codeVerifier]);
325
325
} else {
326
326
reject ([self getErrorCode: error defaultCode: @" authentication_failed" ],
327
- [error localizedDescription ], error);
327
+ [self getErrorMessage: error ], error);
328
328
}
329
329
}]; // end [OIDAuthState presentAuthorizationRequest:request
330
330
} else {
@@ -340,7 +340,8 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
340
340
resolve ([self formatResponse: authState.lastTokenResponse
341
341
withAuthResponse: authState.lastAuthorizationResponse]);
342
342
} else {
343
- reject (@" authentication_failed" , [error localizedDescription ], error);
343
+ reject ([self getErrorCode: error defaultCode: @" authentication_failed" ],
344
+ [self getErrorMessage: error], error);
344
345
}
345
346
}]; // end [OIDAuthState authStateByPresentingAuthorizationRequest:request
346
347
}
@@ -378,7 +379,7 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
378
379
resolve ([self formatResponse: response]);
379
380
} else {
380
381
reject ([self getErrorCode: error defaultCode: @" token_refresh_failed" ],
381
- [error localizedDescription ], error);
382
+ [self getErrorMessage: error ], error);
382
383
}
383
384
}];
384
385
}
@@ -389,7 +390,7 @@ - (void) configureUrlSession: (NSDictionary*) headers {
389
390
if (headers != nil ) {
390
391
configuration.HTTPAdditionalHeaders = headers;
391
392
}
392
-
393
+
393
394
NSURLSession * session = [NSURLSession sessionWithConfiguration: configuration];
394
395
[OIDURLSessionProvider setSession: session];
395
396
}
@@ -466,13 +467,13 @@ - (NSDictionary*)formatResponse: (OIDTokenResponse*) response
466
467
@" scopes" : authResponse.scope ? [authResponse.scope componentsSeparatedByString: @" " ] : [NSArray new ],
467
468
};
468
469
}
469
-
470
+
470
471
- (NSDictionary *)formatRegistrationResponse : (OIDRegistrationResponse*) response {
471
472
NSDateFormatter *dateFormat = [[NSDateFormatter alloc ] init ];
472
473
dateFormat.timeZone = [NSTimeZone timeZoneWithAbbreviation: @" UTC" ];
473
474
[dateFormat setLocale: [NSLocale localeWithLocaleIdentifier: @" en_US_POSIX" ]];
474
475
[dateFormat setDateFormat: @" yyyy-MM-dd'T'HH:mm:ss'Z'" ];
475
-
476
+
476
477
return @{@" clientId" : response.clientID ,
477
478
@" additionalParameters" : response.additionalParameters ,
478
479
@" clientIdIssuedAt" : response.clientIDIssuedAt ? [dateFormat stringFromDate: response.clientIDIssuedAt] : @" " ,
@@ -531,4 +532,16 @@ - (NSString*)getErrorCode: (NSError*) error defaultCode: (NSString *) defaultCod
531
532
return defaultCode;
532
533
}
533
534
535
+ - (NSString *)getErrorMessage : (NSError *) error {
536
+ NSDictionary * userInfo = [error userInfo ];
537
+
538
+ if (userInfo &&
539
+ userInfo[OIDOAuthErrorResponseErrorKey] &&
540
+ userInfo[OIDOAuthErrorResponseErrorKey][OIDOAuthErrorFieldErrorDescription]) {
541
+ return userInfo[OIDOAuthErrorResponseErrorKey][OIDOAuthErrorFieldErrorDescription];
542
+ } else {
543
+ return [error localizedDescription ];
544
+ }
545
+ }
546
+
534
547
@end
0 commit comments