@@ -88,6 +88,7 @@ - (dispatch_queue_t)methodQueue
8888 scopes: (NSArray *) scopes
8989 additionalParameters: (NSDictionary *_Nullable) additionalParameters
9090 serviceConfiguration: (NSDictionary *_Nullable) serviceConfiguration
91+ skipCodeExchange: (BOOL ) skipCodeExchange
9192 useNonce: (BOOL *) useNonce
9293 usePKCE: (BOOL *) usePKCE
9394 resolve: (RCTPromiseResolveBlock) resolve
@@ -104,6 +105,7 @@ - (dispatch_queue_t)methodQueue
104105 useNonce: useNonce
105106 usePKCE: usePKCE
106107 additionalParameters: additionalParameters
108+ skipCodeExchange: skipCodeExchange
107109 resolve: resolve
108110 reject: reject];
109111 } else {
@@ -121,6 +123,7 @@ - (dispatch_queue_t)methodQueue
121123 useNonce: useNonce
122124 usePKCE: usePKCE
123125 additionalParameters: additionalParameters
126+ skipCodeExchange: skipCodeExchange
124127 resolve: resolve
125128 reject: reject];
126129 }];
@@ -259,6 +262,7 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
259262 useNonce : (BOOL *) useNonce
260263 usePKCE : (BOOL *) usePKCE
261264 additionalParameters : (NSDictionary *_Nullable) additionalParameters
265+ skipCodeExchange : (BOOL ) skipCodeExchange
262266 resolve : (RCTPromiseResolveBlock) resolve
263267 reject : (RCTPromiseRejectBlock) reject
264268{
@@ -296,24 +300,39 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
296300 taskId = UIBackgroundTaskInvalid;
297301 }];
298302
299- _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest: request
303+ if (skipCodeExchange) {
304+ _currentSession = [OIDAuthorizationService presentAuthorizationRequest: request
300305 presentingViewController: appDelegate.window.rootViewController
301- callback: ^(OIDAuthState *_Nullable authState,
302- NSError *_Nullable error) {
306+ callback: ^(OIDAuthorizationResponse *_Nullable authorizationResponse, NSError *_Nullable error) {
303307 typeof (self) strongSelf = weakSelf;
304308 strongSelf->_currentSession = nil ;
305309 [UIApplication.sharedApplication endBackgroundTask: taskId];
306310 taskId = UIBackgroundTaskInvalid;
307- if (authState) {
308- resolve ([self formatResponse: authState.lastTokenResponse
309- withAuthResponse: authState.lastAuthorizationResponse]);
311+ if (authorizationResponse) {
312+ resolve ([self formatAuthorizationResponse: authorizationResponse]);
310313 } else {
311314 reject (@" authentication_failed" , [error localizedDescription ], error);
312315 }
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+ }
314334}
315335
316-
317336/*
318337 * Refresh a token with provided OIDServiceConfiguration
319338 */
@@ -350,6 +369,27 @@ - (void)refreshWithConfiguration: (OIDServiceConfiguration *)configuration
350369 }];
351370}
352371
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+
353393/*
354394 * Take raw OIDTokenResponse and turn it to a token response format to pass to JavaScript caller
355395 */
0 commit comments