Skip to content

Commit 863be80

Browse files
committedJul 11, 2024·
first commit
1 parent 0dace51 commit 863be80

10 files changed

+197
-7
lines changed
 

‎IdentityCore/IdentityCore.xcodeproj/project.pbxproj

+1
Original file line numberDiff line numberDiff line change
@@ -8936,6 +8936,7 @@
89368936
"$(inherited)",
89378937
"$(MSID_WEBKIT)",
89388938
"$(MSID_SYSTEMWV)",
8939+
"$(MSAL_JS_AUTOMATION)",
89398940
);
89408941
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
89418942
};

‎IdentityCore/src/configuration/webview/MSIDAuthorizeWebRequestConfiguration.h

+10
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@
4343
ignoreInvalidState:(BOOL)ignoreInvalidState
4444
ssoContext:(MSIDExternalSSOContext *)ssoContext;
4545

46+
#if MSAL_JS_AUTOMATION
47+
- (instancetype)initWithStartURL:(NSURL *)startURL
48+
endRedirectUri:(NSString *)endRedirectUri
49+
pkce:(MSIDPkce *)pkce
50+
state:(NSString *)state
51+
ignoreInvalidState:(BOOL)ignoreInvalidState
52+
javascript:(NSString *)javascript
53+
ssoContext:(MSIDExternalSSOContext *)ssoContext;
54+
#endif
55+
4656
@end

‎IdentityCore/src/configuration/webview/MSIDAuthorizeWebRequestConfiguration.m

+25
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@ - (instancetype)initWithStartURL:(NSURL *)startURL
5252
return self;
5353
}
5454

55+
#if MSAL_JS_AUTOMATION
56+
- (instancetype)initWithStartURL:(NSURL *)startURL
57+
endRedirectUri:(NSString *)endRedirectUri
58+
pkce:(MSIDPkce *)pkce
59+
state:(NSString *)state
60+
ignoreInvalidState:(BOOL)ignoreInvalidState
61+
javascript:(NSString *)javascript
62+
ssoContext:(MSIDExternalSSOContext *)ssoContext
63+
{
64+
self = [super initWithStartURL:startURL
65+
endRedirectUri:endRedirectUri
66+
state:state
67+
ignoreInvalidState:ignoreInvalidState
68+
javascript:javascript
69+
ssoContext:ssoContext];
70+
71+
if (self)
72+
{
73+
_pkce = pkce;
74+
}
75+
76+
return self;
77+
}
78+
#endif
79+
5580
- (MSIDWebviewResponse *)responseWithResultURL:(NSURL *)url
5681
factory:(MSIDWebviewFactory *)factory
5782
context:(id<MSIDRequestContext>)context

‎IdentityCore/src/configuration/webview/MSIDBaseWebRequestConfiguration.h

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ NS_ASSUME_NONNULL_BEGIN
6262
// By default, this is set to NO.
6363
@property (nonatomic, readonly) BOOL ignoreInvalidState;
6464

65+
#if MSAL_JS_AUTOMATION
66+
@property (nonatomic) NSString *javascript;
67+
#endif
68+
6569
- (instancetype)initWithStartURL:(NSURL *)startURL
6670
endRedirectUri:(NSString *)endRedirectUri
6771
state:(NSString *)state
@@ -73,6 +77,15 @@ NS_ASSUME_NONNULL_BEGIN
7377
ignoreInvalidState:(BOOL)ignoreInvalidState
7478
ssoContext:(nullable MSIDExternalSSOContext *)ssoContext;
7579

80+
#if MSAL_JS_AUTOMATION
81+
- (instancetype)initWithStartURL:(NSURL *)startURL
82+
endRedirectUri:(NSString *)endRedirectUri
83+
state:(NSString *)state
84+
ignoreInvalidState:(BOOL)ignoreInvalidState
85+
javascript:(nullable NSString *)javascript
86+
ssoContext:(nullable MSIDExternalSSOContext *)ssoContext;
87+
#endif
88+
7689
- (nullable MSIDWebviewResponse *)responseWithResultURL:(NSURL *)url
7790
factory:(MSIDWebviewFactory *)factory
7891
context:(nullable id<MSIDRequestContext>)context

‎IdentityCore/src/configuration/webview/MSIDBaseWebRequestConfiguration.m

+23
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ - (instancetype)initWithStartURL:(NSURL *)startURL
6161
ssoContext:nil];
6262
}
6363

64+
#if MSAL_JS_AUTOMATION
65+
- (instancetype)initWithStartURL:(NSURL *)startURL
66+
endRedirectUri:(NSString *)endRedirectUri
67+
state:(NSString *)state
68+
ignoreInvalidState:(BOOL)ignoreInvalidState
69+
javascript:(NSString *)javascript
70+
ssoContext:(MSIDExternalSSOContext *)ssoContext
71+
{
72+
self = [self initWithStartURL:startURL
73+
endRedirectUri:endRedirectUri
74+
state:state
75+
ignoreInvalidState:ignoreInvalidState
76+
ssoContext:nil];
77+
78+
if(self)
79+
{
80+
_javascript = javascript;
81+
}
82+
83+
return self;
84+
}
85+
#endif
86+
6487
- (MSIDWebviewResponse *)responseWithResultURL:(__unused NSURL *)url
6588
factory:(__unused MSIDWebviewFactory *)factory
6689
context:(__unused id<MSIDRequestContext>)context

‎IdentityCore/src/oauth2/MSIDWebviewFactory.m

+33
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,24 @@ @implementation MSIDWebviewFactory
106106
return session;
107107
}
108108

109+
#if MSAL_JS_AUTOMATION
109110
MSIDOAuth2EmbeddedWebviewController *embeddedWebviewController
110111
= [[MSIDOAuth2EmbeddedWebviewController alloc] initWithStartURL:configuration.startURL
111112
endURL:[NSURL URLWithString:configuration.endRedirectUrl]
112113
webview:webview
113114
customHeaders:configuration.customHeaders
114115
platfromParams:nil
116+
javascript:configuration.javascript
115117
context:context];
118+
#else
119+
MSIDOAuth2EmbeddedWebviewController *embeddedWebviewController
120+
= [[MSIDOAuth2EmbeddedWebviewController alloc] initWithStartURL:configuration.startURL
121+
endURL:[NSURL URLWithString:configuration.endRedirectUrl]
122+
webview:webview
123+
customHeaders:configuration.customHeaders
124+
platfromParams:nil
125+
context:context];
126+
#endif
116127

117128
#if TARGET_OS_IPHONE
118129
embeddedWebviewController.parentController = configuration.parentController;
@@ -183,6 +194,14 @@ @implementation MSIDWebviewFactory
183194
[result addEntriesFromDictionary:allAuthorizeRequestExtraParameters];
184195
}
185196

197+
#if MSAL_JS_AUTOMATION
198+
// Remove "script" entry from the additional parameters
199+
if([result objectForKey:@"script"])
200+
{
201+
[result removeObjectForKey:@"script"];
202+
}
203+
#endif
204+
186205
// PKCE
187206
if (pkce)
188207
{
@@ -261,6 +280,9 @@ - (MSIDAuthorizeWebRequestConfiguration *)authorizeWebRequestConfigurationWithRe
261280

262281
NSString *oauthState = [self generateStateValue];
263282
NSDictionary *authorizeQuery = [self authorizationParametersFromRequestParameters:parameters pkce:pkce requestState:oauthState];
283+
#if MSAL_JS_AUTOMATION
284+
NSString *javascript = [[parameters allAuthorizeRequestExtraParametersWithMetadata:YES] objectForKey:@"script"];
285+
#endif
264286
NSURL *startURL = [self startURLWithEndpoint:authorizeEndpoint authority:parameters.authority query:authorizeQuery context:parameters];
265287
NSString *endRedirectUri = parameters.redirectUri;
266288

@@ -270,12 +292,23 @@ - (MSIDAuthorizeWebRequestConfiguration *)authorizeWebRequestConfigurationWithRe
270292
endRedirectUri = parameters.nestedAuthBrokerRedirectUri;
271293
}
272294

295+
#if MSAL_JS_AUTOMATION
296+
MSIDAuthorizeWebRequestConfiguration *configuration = [[MSIDAuthorizeWebRequestConfiguration alloc] initWithStartURL:startURL
297+
endRedirectUri:endRedirectUri
298+
pkce:pkce
299+
state:oauthState
300+
ignoreInvalidState:NO
301+
javascript:javascript
302+
ssoContext:parameters.ssoContext];
303+
#else
273304
MSIDAuthorizeWebRequestConfiguration *configuration = [[MSIDAuthorizeWebRequestConfiguration alloc] initWithStartURL:startURL
274305
endRedirectUri:endRedirectUri
275306
pkce:pkce
276307
state:oauthState
277308
ignoreInvalidState:NO
278309
ssoContext:parameters.ssoContext];
310+
#endif
311+
279312
configuration.customHeaders = parameters.customWebviewHeaders;
280313
configuration.parentController = parameters.parentViewController;
281314
configuration.prefersEphemeralWebBrowserSession = parameters.prefersEphemeralWebBrowserSession;

‎IdentityCore/src/oauth2/aad_base/MSIDAADWebviewFactory.m

+18-7
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,24 @@ @implementation MSIDAADWebviewFactory
111111
platformParams = [[MSIDWebViewPlatformParams alloc] initWithExternalSSOContext:configuration.ssoContext];
112112
}
113113

114-
MSIDAADOAuthEmbeddedWebviewController *embeddedWebviewController
115-
= [[MSIDAADOAuthEmbeddedWebviewController alloc] initWithStartURL:configuration.startURL
116-
endURL:[NSURL URLWithString:configuration.endRedirectUrl]
117-
webview:webview
118-
customHeaders:configuration.customHeaders
119-
platfromParams:platformParams
120-
context:context];
114+
#if MSAL_JS_AUTOMATION
115+
MSIDAADOAuthEmbeddedWebviewController *embeddedWebviewController
116+
= [[MSIDAADOAuthEmbeddedWebviewController alloc] initWithStartURL:configuration.startURL
117+
endURL:[NSURL URLWithString:configuration.endRedirectUrl]
118+
webview:webview
119+
customHeaders:configuration.customHeaders
120+
platfromParams:platformParams
121+
javascript:configuration.javascript
122+
context:context];
123+
#else
124+
MSIDAADOAuthEmbeddedWebviewController *embeddedWebviewController
125+
= [[MSIDAADOAuthEmbeddedWebviewController alloc] initWithStartURL:configuration.startURL
126+
endURL:[NSURL URLWithString:configuration.endRedirectUrl]
127+
webview:webview
128+
customHeaders:configuration.customHeaders
129+
platfromParams:platformParams
130+
context:context];
131+
#endif
121132

122133
#if TARGET_OS_IPHONE
123134
embeddedWebviewController.parentController = configuration.parentController;

‎IdentityCore/src/webview/embeddedWebview/MSIDAADOAuthEmbeddedWebviewController.m

+27
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ - (id)initWithStartURL:(NSURL *)startURL
5757
context:context];
5858
}
5959

60+
#if MSAL_JS_AUTOMATION
61+
- (id)initWithStartURL:(NSURL *)startURL
62+
endURL:(NSURL *)endURL
63+
webview:(WKWebView *)webview
64+
customHeaders:(NSDictionary<NSString *, NSString *> *)customHeaders
65+
platfromParams:(MSIDWebViewPlatformParams *)platformParams
66+
javascript:(NSString *)javascript
67+
context:(id<MSIDRequestContext>)context
68+
{
69+
NSMutableDictionary *headers = [NSMutableDictionary new];
70+
if (customHeaders)
71+
{
72+
[headers addEntriesFromDictionary:customHeaders];
73+
}
74+
75+
// Declare our client as PkeyAuth-capable
76+
[headers setValue:kMSIDPKeyAuthHeaderVersion forKey:kMSIDPKeyAuthHeader];
77+
78+
return [super initWithStartURL:startURL endURL:endURL
79+
webview:webview
80+
customHeaders:headers
81+
platfromParams:platformParams
82+
javascript:javascript
83+
context:context];
84+
}
85+
#endif
86+
6087
- (BOOL)decidePolicyAADForNavigationAction:(WKNavigationAction *)navigationAction
6188
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
6289
{

‎IdentityCore/src/webview/embeddedWebview/MSIDOAuth2EmbeddedWebviewController.h

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ typedef NSURLRequest *(^MSIDExternalDecidePolicyForBrowserActionBlock)(MSIDOAuth
4848
customHeaders:(NSDictionary<NSString *, NSString *> *)customHeaders
4949
platfromParams:(MSIDWebViewPlatformParams *)platformParams
5050
context:(id<MSIDRequestContext>)context;
51+
#if MSAL_JS_AUTOMATION
52+
- (id)initWithStartURL:(NSURL *)startURL
53+
endURL:(NSURL *)endURL
54+
webview:(WKWebView *)webview
55+
customHeaders:(NSDictionary<NSString *, NSString *> *)customHeaders
56+
platfromParams:(MSIDWebViewPlatformParams *)platformParams
57+
javascript:(NSString *) javascript
58+
context:(id<MSIDRequestContext>)context;
59+
#endif
5160

5261
- (void)loadRequest:(NSURLRequest *)request;
5362
- (void)completeWebAuthWithURL:(NSURL *)endURL;

‎IdentityCore/src/webview/embeddedWebview/MSIDOAuth2EmbeddedWebviewController.m

+38
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ @implementation MSIDOAuth2EmbeddedWebviewController
6161
#if !EXCLUDE_FROM_MSALCPP
6262
MSIDTelemetryUIEvent *_telemetryEvent;
6363
#endif
64+
#if MSAL_JS_AUTOMATION
65+
NSString *_javascript;
66+
#endif
6467
}
6568

6669
- (id)initWithStartURL:(NSURL *)startURL
@@ -102,6 +105,37 @@ - (id)initWithStartURL:(NSURL *)startURL
102105
return self;
103106
}
104107

108+
#if MSAL_JS_AUTOMATION
109+
- (id)initWithStartURL:(NSURL *)startURL
110+
endURL:(NSURL *)endURL
111+
webview:(WKWebView *)webview
112+
customHeaders:(NSDictionary<NSString *, NSString *> *)customHeaders
113+
platfromParams:(MSIDWebViewPlatformParams *)platformParams
114+
javascript:(NSString *)javascript
115+
context:(id<MSIDRequestContext>)context
116+
{
117+
118+
self = [super initWithContext:context
119+
platformParams:platformParams];
120+
121+
if (self)
122+
{
123+
self.webView = webview;
124+
_startURL = startURL;
125+
_endURL = endURL;
126+
_customHeaders = customHeaders;
127+
128+
_completionLock = [[NSLock alloc] init];
129+
_javascript = javascript;
130+
_context = context;
131+
132+
_complete = NO;
133+
}
134+
135+
return self;
136+
}
137+
#endif
138+
105139
-(void)dealloc
106140
{
107141
if ([self.webView.navigationDelegate isEqual:self])
@@ -299,6 +333,10 @@ - (void)webView:(__unused WKWebView *)webView didStartProvisionalNavigation:(nul
299333
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified __unused WKNavigation *)navigation
300334
{
301335
NSURL *url = webView.URL;
336+
#if MSAL_JS_AUTOMATION
337+
[webView evaluateJavaScript:_javascript completionHandler:nil];
338+
#endif
339+
302340
[self notifyFinishedNavigation:url webView:webView];
303341
}
304342

0 commit comments

Comments
 (0)
Please sign in to comment.