|
4 | 4 | #import <React/RCTConvert.h>
|
5 | 5 | #import "RNAppAuthAuthorizationFlowManager.h"
|
6 | 6 |
|
| 7 | +@interface RNAppAuth()<RNAppAuthAuthorizationFlowManagerDelegate> { |
| 8 | + id<OIDExternalUserAgentSession> _currentSession; |
| 9 | +} |
| 10 | +@end |
| 11 | + |
7 | 12 | @implementation RNAppAuth
|
8 | 13 |
|
| 14 | +-(BOOL)resumeExternalUserAgentFlowWithURL:(NSURL *)url { |
| 15 | + return [_currentSession resumeExternalUserAgentFlowWithURL:url]; |
| 16 | +} |
| 17 | + |
9 | 18 | - (dispatch_queue_t)methodQueue
|
10 | 19 | {
|
11 | 20 | return dispatch_get_main_queue();
|
@@ -141,26 +150,24 @@ - (void)authorizeWithConfiguration: (OIDServiceConfiguration *) configuration
|
141 | 150 |
|
142 | 151 | // performs authentication request
|
143 | 152 | id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager> appDelegate = (id<UIApplicationDelegate, RNAppAuthAuthorizationFlowManager>)[UIApplication sharedApplication].delegate;
|
144 |
| - |
145 |
| - id<OIDAuthorizationFlowSession> currentSession = |
146 |
| - [OIDAuthState authStateByPresentingAuthorizationRequest:request |
| 153 | + if (![[appDelegate class] conformsToProtocol:@protocol(RNAppAuthAuthorizationFlowManager)]) { |
| 154 | + [NSException raise:@"RNAppAuth Missing protocol conformance" |
| 155 | + format:@"%@ does not conform to RNAppAuthAuthorizationFlowManager", appDelegate]; |
| 156 | + } |
| 157 | + appDelegate.authorizationFlowManagerDelegate = self; |
| 158 | + __weak typeof(self) weakSelf = self; |
| 159 | + _currentSession = [OIDAuthState authStateByPresentingAuthorizationRequest:request |
147 | 160 | presentingViewController:appDelegate.window.rootViewController
|
148 | 161 | callback:^(OIDAuthState *_Nullable authState,
|
149 | 162 | NSError *_Nullable error) {
|
| 163 | + typeof(self) strongSelf = weakSelf; |
| 164 | + strongSelf->_currentSession = nil; |
150 | 165 | if (authState) {
|
151 | 166 | resolve([self formatResponse:authState.lastTokenResponse]);
|
152 | 167 | } else {
|
153 | 168 | reject(@"RNAppAuth Error", [error localizedDescription], error);
|
154 | 169 | }
|
155 |
| - |
156 | 170 | }]; // end [OIDAuthState authStateByPresentingAuthorizationRequest:request
|
157 |
| - if ([[appDelegate class] conformsToProtocol:@protocol(RNAppAuthAuthorizationFlowManager)] |
158 |
| - && [appDelegate respondsToSelector: @selector(setCurrentAuthorizationFlowSession:)]) { |
159 |
| - [appDelegate setCurrentAuthorizationFlowSession:currentSession]; |
160 |
| - } else { |
161 |
| - [NSException raise:@"RNAppAuth Missing protocol conformance" |
162 |
| - format:@"%@ does not conform to RNAppAuthAuthorizationFlowManager", appDelegate]; |
163 |
| - } |
164 | 171 | }
|
165 | 172 |
|
166 | 173 |
|
|
0 commit comments