@@ -61,82 +61,93 @@ - (BOOL)presentExternalUserAgentRequest:(id<OIDExternalUserAgentRequest>)request
61
61
62
62
_externalUserAgentFlowInProgress = YES ;
63
63
_session = session;
64
- BOOL openedSafari = NO ;
64
+ BOOL openedUserAgent = NO ;
65
65
NSURL *requestURL = [request externalUserAgentRequestURL ];
66
66
67
67
// iOS 12 and later, use ASWebAuthenticationSession
68
68
if (@available (iOS 12.0 , *)) {
69
- __weak OIDExternalUserAgentIOS *weakSelf = self;
70
- NSString *redirectScheme = request.redirectScheme ;
71
- ASWebAuthenticationSession *authenticationVC =
72
- [[ASWebAuthenticationSession alloc ] initWithURL: requestURL
73
- callbackURLScheme: redirectScheme
74
- completionHandler: ^(NSURL * _Nullable callbackURL,
75
- NSError * _Nullable error) {
76
- __strong OIDExternalUserAgentIOS *strongSelf = weakSelf;
77
- if (!strongSelf) {
78
- return ;
79
- }
80
- strongSelf->_webAuthenticationVC = nil ;
81
- if (callbackURL) {
82
- [strongSelf->_session resumeExternalUserAgentFlowWithURL: callbackURL];
83
- } else {
84
- NSError *safariError =
85
- [OIDErrorUtilities errorWithCode: OIDErrorCodeUserCanceledAuthorizationFlow
86
- underlyingError: error
87
- description: nil ];
88
- [strongSelf->_session failExternalUserAgentFlowWithError: safariError];
89
- }
90
- }];
91
- _webAuthenticationVC = authenticationVC;
92
- openedSafari = [authenticationVC start ];
69
+ // ASWebAuthenticationSession doesn't work with guided access (rdar://40809553)
70
+ if (!UIAccessibilityIsGuidedAccessEnabled ()) {
71
+ __weak OIDExternalUserAgentIOS *weakSelf = self;
72
+ NSString *redirectScheme = request.redirectScheme ;
73
+ ASWebAuthenticationSession *authenticationVC =
74
+ [[ASWebAuthenticationSession alloc ] initWithURL: requestURL
75
+ callbackURLScheme: redirectScheme
76
+ completionHandler: ^(NSURL * _Nullable callbackURL,
77
+ NSError * _Nullable error) {
78
+ __strong OIDExternalUserAgentIOS *strongSelf = weakSelf;
79
+ if (!strongSelf) {
80
+ return ;
81
+ }
82
+ strongSelf->_webAuthenticationVC = nil ;
83
+ if (callbackURL) {
84
+ [strongSelf->_session resumeExternalUserAgentFlowWithURL: callbackURL];
85
+ } else {
86
+ NSError *safariError =
87
+ [OIDErrorUtilities errorWithCode: OIDErrorCodeUserCanceledAuthorizationFlow
88
+ underlyingError: error
89
+ description: nil ];
90
+ [strongSelf->_session failExternalUserAgentFlowWithError: safariError];
91
+ }
92
+ }];
93
+ _webAuthenticationVC = authenticationVC;
94
+ openedUserAgent = [authenticationVC start ];
95
+ }
96
+ }
93
97
// iOS 11, use SFAuthenticationSession
94
- } else if (@available (iOS 11.0 , *)) {
95
- __weak OIDExternalUserAgentIOS *weakSelf = self;
96
- NSString *redirectScheme = request.redirectScheme ;
97
- SFAuthenticationSession *authenticationVC =
98
- [[SFAuthenticationSession alloc ] initWithURL: requestURL
99
- callbackURLScheme: redirectScheme
100
- completionHandler: ^(NSURL * _Nullable callbackURL,
101
- NSError * _Nullable error) {
102
- __strong OIDExternalUserAgentIOS *strongSelf = weakSelf;
103
- if (!strongSelf) {
104
- return ;
105
- }
106
- strongSelf->_authenticationVC = nil ;
107
- if (callbackURL) {
108
- [strongSelf->_session resumeExternalUserAgentFlowWithURL: callbackURL];
109
- } else {
110
- NSError *safariError =
111
- [OIDErrorUtilities errorWithCode: OIDErrorCodeUserCanceledAuthorizationFlow
112
- underlyingError: error
113
- description: @" User cancelled." ];
114
- [strongSelf->_session failExternalUserAgentFlowWithError: safariError];
115
- }
116
- }];
117
- _authenticationVC = authenticationVC;
118
- openedSafari = [authenticationVC start ];
98
+ if (@available (iOS 11.0 , *)) {
99
+ // SFAuthenticationSession doesn't work with guided access (rdar://40809553)
100
+ if (!openedUserAgent && !UIAccessibilityIsGuidedAccessEnabled ()) {
101
+ __weak OIDExternalUserAgentIOS *weakSelf = self;
102
+ NSString *redirectScheme = request.redirectScheme ;
103
+ SFAuthenticationSession *authenticationVC =
104
+ [[SFAuthenticationSession alloc ] initWithURL: requestURL
105
+ callbackURLScheme: redirectScheme
106
+ completionHandler: ^(NSURL * _Nullable callbackURL,
107
+ NSError * _Nullable error) {
108
+ __strong OIDExternalUserAgentIOS *strongSelf = weakSelf;
109
+ if (!strongSelf) {
110
+ return ;
111
+ }
112
+ strongSelf->_authenticationVC = nil ;
113
+ if (callbackURL) {
114
+ [strongSelf->_session resumeExternalUserAgentFlowWithURL: callbackURL];
115
+ } else {
116
+ NSError *safariError =
117
+ [OIDErrorUtilities errorWithCode: OIDErrorCodeUserCanceledAuthorizationFlow
118
+ underlyingError: error
119
+ description: @" User cancelled." ];
120
+ [strongSelf->_session failExternalUserAgentFlowWithError: safariError];
121
+ }
122
+ }];
123
+ _authenticationVC = authenticationVC;
124
+ openedUserAgent = [authenticationVC start ];
125
+ }
126
+ }
119
127
// iOS 9 and 10, use SFSafariViewController
120
- } else if (@available (iOS 9.0 , *)) {
121
- SFSafariViewController *safariVC =
122
- [[SFSafariViewController alloc ] initWithURL: requestURL];
123
- safariVC.delegate = self;
124
- _safariVC = safariVC;
125
- [_presentingViewController presentViewController: safariVC animated: YES completion: nil ];
126
- openedSafari = YES ;
128
+ if (@available (iOS 9.0 , *)) {
129
+ if (!openedUserAgent) {
130
+ SFSafariViewController *safariVC =
131
+ [[SFSafariViewController alloc ] initWithURL: requestURL];
132
+ safariVC.delegate = self;
133
+ _safariVC = safariVC;
134
+ [_presentingViewController presentViewController: safariVC animated: YES completion: nil ];
135
+ openedUserAgent = YES ;
136
+ }
137
+ }
127
138
// iOS 8 and earlier, use mobile Safari
128
- } else {
129
- openedSafari = [[UIApplication sharedApplication ] openURL: requestURL];
139
+ if (!openedUserAgent) {
140
+ openedUserAgent = [[UIApplication sharedApplication ] openURL: requestURL];
130
141
}
131
142
132
- if (!openedSafari ) {
143
+ if (!openedUserAgent ) {
133
144
[self cleanUp ];
134
145
NSError *safariError = [OIDErrorUtilities errorWithCode: OIDErrorCodeSafariOpenError
135
146
underlyingError: nil
136
147
description: @" Unable to open Safari." ];
137
148
[session failExternalUserAgentFlowWithError: safariError];
138
149
}
139
- return openedSafari ;
150
+ return openedUserAgent ;
140
151
}
141
152
142
153
- (void )dismissExternalUserAgentAnimated : (BOOL )animated completion : (void (^)(void ))completion {
@@ -154,21 +165,17 @@ - (void)dismissExternalUserAgentAnimated:(BOOL)animated completion:(void (^)(voi
154
165
155
166
[self cleanUp ];
156
167
157
- if (@ available (iOS 12.0 , *) ) {
168
+ if (webAuthenticationVC ) {
158
169
// dismiss the ASWebAuthenticationSession
159
170
[webAuthenticationVC cancel ];
160
171
if (completion) completion ();
161
- } else if (@ available (iOS 11.0 , *) ) {
172
+ } else if (authenticationVC ) {
162
173
// dismiss the SFAuthenticationSession
163
174
[authenticationVC cancel ];
164
175
if (completion) completion ();
165
- } else if (@ available (iOS 9.0 , *) ) {
176
+ } else if (safariVC ) {
166
177
// dismiss the SFSafariViewController
167
- if (safariVC) {
168
- [safariVC dismissViewControllerAnimated: YES completion: completion];
169
- } else {
170
- if (completion) completion ();
171
- }
178
+ [safariVC dismissViewControllerAnimated: YES completion: completion];
172
179
} else {
173
180
if (completion) completion ();
174
181
}
0 commit comments