@@ -88,6 +88,7 @@ - (dispatch_queue_t)methodQueue
88
88
scopes: (NSArray *) scopes
89
89
additionalParameters: (NSDictionary *_Nullable) additionalParameters
90
90
serviceConfiguration: (NSDictionary *_Nullable) serviceConfiguration
91
+ skipCodeExchange: (BOOL ) skipCodeExchange
91
92
useNonce: (BOOL *) useNonce
92
93
usePKCE: (BOOL *) usePKCE
93
94
resolve: (RCTPromiseResolveBlock) resolve
@@ -104,6 +105,7 @@ - (dispatch_queue_t)methodQueue
104
105
useNonce: useNonce
105
106
usePKCE: usePKCE
106
107
additionalParameters: additionalParameters
108
+ skipCodeExchange: skipCodeExchange
107
109
resolve: resolve
108
110
reject: reject];
109
111
} else {
@@ -121,6 +123,7 @@ - (dispatch_queue_t)methodQueue
121
123
useNonce: useNonce
122
124
usePKCE: usePKCE
123
125
additionalParameters: additionalParameters
126
+ skipCodeExchange: skipCodeExchange
124
127
resolve: resolve
125
128
reject: reject];
126
129
}];
@@ -259,6 +262,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
259
262
useNonce : (BOOL *) useNonce
260
263
usePKCE : (BOOL *) usePKCE
261
264
additionalParameters : (NSDictionary *_Nullable) additionalParameters
265
+ skipCodeExchange : (BOOL ) skipCodeExchange
262
266
resolve : (RCTPromiseResolveBlock) resolve
263
267
reject : (RCTPromiseRejectBlock) reject
264
268
{
@@ -296,24 +300,39 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
296
300
taskId = UIBackgroundTaskInvalid;
297
301
}];
298
302
299
- _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest: request
303
+ if (skipCodeExchange) {
304
+ _currentSession = [OIDAuthorizationService presentAuthorizationRequest: request
300
305
presentingViewController: appDelegate.window.rootViewController
301
- callback: ^(OIDAuthState *_Nullable authState,
302
- NSError *_Nullable error) {
306
+ callback: ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) {
303
307
typeof (self) strongSelf = weakSelf;
304
308
strongSelf->_currentSession = nil ;
305
309
[UIApplication.sharedApplication endBackgroundTask: taskId];
306
310
taskId = UIBackgroundTaskInvalid;
307
- if (authState) {
308
- resolve ([self formatResponse: authState.lastTokenResponse
309
- withAuthResponse: authState.lastAuthorizationResponse]);
311
+ if (authorizationResponse) {
312
+ resolve ([self formatAuthorizationResponse: authorizationResponse]);
310
313
} else {
311
314
reject (@" authentication_failed" , [error localizedDescription ], error);
312
315
}
313
- }]; // end [OIDAuthState authStateByPresentingAuthorizationRequest:request
316
+ }]; // end [OIDAuthState presentAuthorizationRequest:request
317
+ } else {
318
+ _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest: request
319
+ presentingViewController: appDelegate.window.rootViewController
320
+ callback: ^(OIDAuthState *_Nullable authState,
321
+ NSError *_Nullable error) {
322
+ typeof (self) strongSelf = weakSelf;
323
+ strongSelf->_currentSession = nil ;
324
+ [UIApplication.sharedApplication endBackgroundTask: taskId];
325
+ taskId = UIBackgroundTaskInvalid;
326
+ if (authState) {
327
+ resolve ([self formatResponse: authState.lastTokenResponse
328
+ withAuthResponse: authState.lastAuthorizationResponse]);
329
+ } else {
330
+ reject (@" authentication_failed" , [error localizedDescription ], error);
331
+ }
332
+ }]; // end [OIDAuthState authStateByPresentingAuthorizationRequest:request
333
+ }
314
334
}
315
335
316
-
317
336
/*
318
337
* Refresh a token with provided OIDServiceConfiguration
319
338
*/
@@ -350,6 +369,27 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
350
369
}];
351
370
}
352
371
372
+
373
+ /*
374
+ * Take raw OIDAuthorizationResponse and turn it to response format to pass to JavaScript caller
375
+ */
376
+ - (NSDictionary *)formatAuthorizationResponse : (OIDAuthorizationResponse*) response {
377
+ NSDateFormatter *dateFormat = [[NSDateFormatter alloc ] init ];
378
+ dateFormat.timeZone = [NSTimeZone timeZoneWithAbbreviation: @" UTC" ];
379
+ [dateFormat setLocale: [NSLocale localeWithLocaleIdentifier: @" en_US_POSIX" ]];
380
+ [dateFormat setDateFormat: @" yyyy-MM-dd'T'HH:mm:ss'Z'" ];
381
+
382
+ return @{@" authorizationCode" : response.authorizationCode ? response.authorizationCode : @" " ,
383
+ @" state" : response.state ? response.state : @" " ,
384
+ @" accessToken" : response.accessToken ? response.accessToken : @" " ,
385
+ @" accessTokenExpirationDate" : response.accessTokenExpirationDate ? [dateFormat stringFromDate: response.accessTokenExpirationDate] : @" " ,
386
+ @" tokenType" : response.tokenType ? response.tokenType : @" " ,
387
+ @" idToken" : response.idToken ? response.idToken : @" " ,
388
+ @" scopes" : response.scope ? [response.scope componentsSeparatedByString: @" " ] : [NSArray new ],
389
+ @" additionalParameters" : response.additionalParameters ,
390
+ };
391
+ }
392
+
353
393
/*
354
394
* Take raw OIDTokenResponse and turn it to a token response format to pass to JavaScript caller
355
395
*/
0 commit comments