Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit 7415bc6

Browse files
author
Chase Crawford
committed
Added Web and iOS Plugin Fixes
1 parent f9d084e commit 7415bc6

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

src/msal-capacitor-plugin/README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Using `useContext` hook we will implement an auth provider that will wrap our ap
103103
}, []);
104104

105105
const initializeOptions = async() => {
106-
let uri = isPlatform('capacitor') ? 'ios redirect url' : 'http://localhost:3000';
106+
let uri = isPlatform('capacitor') ? 'msauth.{Bundle ID}://auth' : 'http://localhost:3000';
107107
console.log(uri);
108108
(await MsalCap.setOptions({
109109
clientId: 'Client Id',
@@ -226,6 +226,39 @@ Using `useContext` hook we will implement an auth provider that will wrap our ap
226226
export default AuthContext;
227227
```
228228

229+
### 3. Update AppDelegate.swift file in App Folder of ios platform
230+
Because the Capacitor Callback bridge can't handle a redirect from a broker applicaiton we need to add the MSALPublicClientApplication Handler response to the ui return.
231+
232+
This happens when redirect are in applications like Microsoft Authenticator.
233+
234+
235+
- Find the following applicaiton method below
236+
237+
```swift
238+
239+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
240+
// Called when the app was launched with a url. Feel free to add additional processing here,
241+
242+
return CAPBridge.handleOpenUrl(url, options)
243+
}
244+
245+
```
246+
- Add the following code
247+
248+
```swift
249+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
250+
// Called when the app was launched with a url. Feel free to add additional processing here,
251+
252+
var response = false
253+
254+
response = MSALPublicClientApplication.handleMSALRespobse((url), sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String)
255+
response = CAPBridge.handleOpenUrl(url, options)
256+
257+
return response
258+
}
259+
260+
```
261+
229262
---
230263

231264

src/msal-capacitor-plugin/ios/Plugin/Plugin.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ public class MsalPlugin: CAPPlugin {
3333

3434
@objc func setOptions(_ call: CAPPluginCall) {
3535
do {
36-
// 1. Sometimes Javascripts Apps cause re-renders resulting in options being set again
37-
// This protects from options being set again
38-
if (call.getBool("guardForRerenders") ?? false) == true && self.msalHasOptions == true {
36+
// 1. Sometimes Javascripts Apps cause re-renders resulting in options being set again. This protects from options being set again
37+
if (call.getBool("rerenderGuard") ?? false) == true && self.msalHasOptions == true {
3938
return
4039
}
4140

@@ -94,7 +93,6 @@ public class MsalPlugin: CAPPlugin {
9493
}
9594
}
9695

97-
9896
@objc func acquireAccessTokenForUser(_ call: CAPPluginCall) {
9997
// 1. Check if Options have been set
10098
if self.msalHasOptions == false {
@@ -105,8 +103,7 @@ public class MsalPlugin: CAPPlugin {
105103
if self.msalAuthenticated == true {
106104
// 2.
107105
let msalParameters = MSALParameters()
108-
msalParameters.completionBlockQueue = DispatchQueue.main
109-
106+
110107
self.msalClient?.getCurrentAccount(with: msalParameters, completionBlock: { (currentAccount, previousAccount, error) in
111108
if let currentAccount = currentAccount {
112109
self.msalAccount = currentAccount
@@ -271,7 +268,6 @@ public class MsalPlugin: CAPPlugin {
271268
if let completion = completion {
272269
completion(nil)
273270
}
274-
275271
return
276272
}
277273

@@ -291,7 +287,6 @@ public class MsalPlugin: CAPPlugin {
291287
})
292288
}
293289

294-
295290
private func logoutInteractive(_ call: CAPPluginCall) {
296291
do {
297292
// 1. Set Web View Parameters for iOS or macos
@@ -330,8 +325,8 @@ public class MsalPlugin: CAPPlugin {
330325
#endif
331326

332327
let parameters = MSALInteractiveTokenParameters(scopes: self.msalPopupScopes!, webviewParameters: webViewParameters)
333-
parameters.promptType = .default
334-
parameters.completionBlockQueue = DispatchQueue.main
328+
parameters.webviewParameters.webviewType = .wkWebView
329+
parameters.promptType = .selectAccount
335330

336331
// 3. Acquire Token view Redirect Login through Microsft Identity Platform
337332
self.msalClient?.acquireToken(with: parameters) { (response, error) in

src/msal-capacitor-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@assimalign/msal-capacitor-plugin",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "A custom Capacitor Plugin for MSAL targeting Web and IOS Platforms",
55
"main": "dist/index.js",
66
"module": "dist/esm/index.js",

src/msal-capacitor-plugin/src/definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface IMsalPluginOptions {
3737
webOptions?: IMsalWebPluginOptions;
3838
iosOptions?: IMsalIosPluginOptions;
3939
androidOptions?: IMsalAndroidPluginOptions;
40-
guardForRerenders?: boolean;
40+
rerenderGuard?: boolean;
4141
}
4242

4343
export interface IMsalPlugin {

src/msal-capacitor-plugin/src/web.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class MsalPluginWeb extends WebPlugin implements IMsalPlugin {
2626
try {
2727
if(options) {
2828

29-
if(options.guardForRerenders === true) {
29+
if (options.rerenderGuard === true && this.msalHasOptions == true) {
3030
return
3131
}
3232

0 commit comments

Comments
 (0)