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

Commit f9d084e

Browse files
author
Chase Crawford
committed
Merge branch 'users/ccrawford/ios.web.fixes' of https://github.com/Assimalign-LLC/assim-js-packages into users/ccrawford/ios.web.fixes
2 parents 3b42a12 + 8ddd73d commit f9d084e

File tree

11 files changed

+103
-56
lines changed

11 files changed

+103
-56
lines changed

src/msal-capacitor-plugin-demo/ios/App/App.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,12 @@
349349
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
350350
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
351351
CODE_SIGN_STYLE = Automatic;
352-
DEVELOPMENT_TEAM = NGDMY4TLA6;
352+
DEVELOPMENT_TEAM = "";
353353
INFOPLIST_FILE = App/Info.plist;
354-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
354+
IPHONEOS_DEPLOYMENT_TARGET = 14.2;
355355
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
356356
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
357-
PRODUCT_BUNDLE_IDENTIFIER = io.ionic.starter;
357+
PRODUCT_BUNDLE_IDENTIFIER = some.bundle.id;
358358
PRODUCT_NAME = "$(TARGET_NAME)";
359359
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG USE_PUSH";
360360
SWIFT_VERSION = 5.0;
@@ -369,11 +369,11 @@
369369
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
370370
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
371371
CODE_SIGN_STYLE = Automatic;
372-
DEVELOPMENT_TEAM = NGDMY4TLA6;
372+
DEVELOPMENT_TEAM = "";
373373
INFOPLIST_FILE = App/Info.plist;
374-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
374+
IPHONEOS_DEPLOYMENT_TARGET = 14.2;
375375
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
376-
PRODUCT_BUNDLE_IDENTIFIER = io.ionic.starter;
376+
PRODUCT_BUNDLE_IDENTIFIER = some.bundle.id;
377377
PRODUCT_NAME = "$(TARGET_NAME)";
378378
SWIFT_ACTIVE_COMPILATION_CONDITIONS = USE_PUSH;
379379
SWIFT_VERSION = 5.0;

src/msal-capacitor-plugin-demo/ios/App/App/App.entitlements

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
<dict>
55
<key>keychain-access-groups</key>
66
<array>
7-
<string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
8-
<string>$(AppIdentifierPrefix)com.microsoft.identity.universalstorage</string>
9-
<string>$(AppIdentifierPrefix)sessionStorage</string>
7+
<string>$(AppIdentifierPrefix)com.company.cache</string>
108
</array>
119
</dict>
1210
</plist>

src/msal-capacitor-plugin-demo/ios/App/App/Info.plist

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>LSApplicationQueriesSchemes</key>
6-
<array>
7-
<string>msauthv2</string>
8-
<string>msauthv3</string>
9-
</array>
10-
<key>NSFaceIDUsageDescription</key>
11-
<string>For an easier and faster log in.</string>
125
<key>CFBundleDevelopmentRegion</key>
136
<string>en</string>
147
<key>CFBundleDisplayName</key>
@@ -33,12 +26,17 @@
3326
<key>CFBundleURLSchemes</key>
3427
<array>
3528
<string>capacitor</string>
36-
<string>msauth.assimalign.MSALiOS</string>
29+
<string></string>
3730
</array>
3831
</dict>
3932
</array>
4033
<key>CFBundleVersion</key>
4134
<string>1</string>
35+
<key>LSApplicationQueriesSchemes</key>
36+
<array>
37+
<string>msauthv2</string>
38+
<string>msauthv3</string>
39+
</array>
4240
<key>LSRequiresIPhoneOS</key>
4341
<true/>
4442
<key>NSAppTransportSecurity</key>
@@ -48,6 +46,8 @@
4846
</dict>
4947
<key>NSCameraUsageDescription</key>
5048
<string>To Take Photos and Video</string>
49+
<key>NSFaceIDUsageDescription</key>
50+
<string>For an easier and faster log in.</string>
5151
<key>NSLocationAlwaysUsageDescription</key>
5252
<string>Always allow Geolocation?</string>
5353
<key>NSLocationWhenInUseUsageDescription</key>

src/msal-capacitor-plugin-demo/ios/App/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def capacitor_pods
1010
# Automatic Capacitor Pod dependencies, do not delete
1111
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
1212
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
13-
pod 'AssimalignMsalCapacitorPlugin', :path => '..\..\..\msal-capacitor-plugin'
13+
pod 'AssimalignMsalCapacitorPlugin', :path => '../../../msal-capacitor-plugin'
1414
# Do not delete
1515
end
1616

src/msal-capacitor-plugin-demo/src/context/auth/AuthContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const useAuthentication = (): IAuthContext => {
2121
}, []);
2222

2323
const initializeOptions = async() => {
24-
let uri = isPlatform('capacitor') ? 'msauth.{iOS MAC redirect Url}://auth' : 'http://localhost:3000';
24+
let uri = isPlatform('capacitor') ? 'msauth.{bundle Id}://auth' : 'http://localhost:3000';
2525
console.log(uri);
2626
(await MsalCap.setOptions({
2727
clientId: '6b51f8a2-d03d-4d86-b753-87b45b89d794',

src/msal-capacitor-plugin/README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ Below are examples are of how to implement an authentication provider that can b
3030
- Step 4 : `npm i @assimalign/msal-capacitor-plugin`
3131
- Step 5 : `ionic cap sync` Downlaoad Package
3232

33+
34+
### Ios Specific Setup: Add keys to info.plist File
35+
```xml
36+
<key>LSApplicationQueriesSchemes</key>
37+
<array>
38+
<string>msauthv2</string>
39+
<string>msauthv3</string>
40+
</array>
41+
<key>CFBundleURLTypes</key>
42+
<array>
43+
<dict>
44+
<key>CFBundleURLName</key>
45+
<string>com.getcapacitor.capacitor</string>
46+
<key>CFBundleURLSchemes</key>
47+
<array>
48+
<string>capacitor</string>
49+
<string><!--The Key Sharing Groups which will be added to XCode--></string>
50+
</array>
51+
</dict>
52+
</array>
53+
<!-- If use Biometric Auth-->
54+
<key>NSFaceIDUsageDescription</key>
55+
<string>For an easier and faster log in.</string>
56+
```
3357
---
3458

3559
## React App Instruction (Typescript)
@@ -61,8 +85,7 @@ Using `useContext` hook we will implement an auth provider that will wrap our ap
6185
import { IAuthContext } from './types';
6286
import { Plugins } from '@capacitor/core';
6387
import { isPlatform } from '@ionic/react';
64-
import { AvailableResult, BiometryType } from 'capacitor-native-biometric';
65-
import '@eastdil/msal-capacitor-plugin';
88+
import '@assimalign/msal-capacitor-plugin';
6689

6790
const AuthContext = createContext<IAuthContext>({
6891
isAuthenticated: () => { },

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

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ import LocalAuthentication
77
public class MsalPlugin: CAPPlugin {
88

99
typealias AccountCompletion = (MSALAccount?) -> Void
10+
11+
var msalInitializationCount = Int()
1012

1113
var msalAccount: MSALAccount?
1214
var msalResults: MSALResult?
1315
var msalClient: MSALPublicClientApplication?
16+
// Struct Initialization Default is False, setting this in setOptions resulted in error due to reset of options when a rerender occurrs
17+
//
1418
var msalAuthenticated = Bool()
1519
var msalUseBiometrics = Bool()
1620
var msalPopupScopes: [String]?
1721
var msalHasOptions = Bool()
22+
1823
var msalLocalAuthContext = LAContext()
1924

2025
var dateFormatter = DateFormatter()
@@ -28,39 +33,48 @@ public class MsalPlugin: CAPPlugin {
2833

2934
@objc func setOptions(_ call: CAPPluginCall) {
3035
do {
31-
// Step 01: Validate all Options have been passed from Plugin bridge
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 {
39+
return
40+
}
41+
42+
// 2. Validate all Options have been passed from Plugin bridge
3243
guard let authorityUri = call.getString("authority") else { return }
3344
guard let clientId = call.getString("clientId") else {return }
3445
guard let redirectUri = call.getString("redirectUri") else {return }
3546
guard let authorityUrl = URL(string: authorityUri ) else {return }
3647

37-
// Step 02: If made it this point, then set & create Configuraitons, Authority, & Public Client
48+
// 3. If made it this point, then set & create Configuraitons, Authority, & Public Client
3849
let clientAuthority = try MSALAADAuthority(url: authorityUrl)
3950
let clientConfiguration = MSALPublicClientApplicationConfig(clientId: clientId, redirectUri: redirectUri, authority: clientAuthority)
4051

52+
// 4. Set iOS Options
4153
if let isoOptions = call.getObject("iosOptions") {
4254
if isoOptions["enableBiometrics"] == nil {
4355
self.msalUseBiometrics = false
4456
} else {
4557
self.msalUseBiometrics = isoOptions["enableBiometrics"] as! Bool;
4658
}
59+
60+
var tokenCache = ""
4761

48-
var tokenCache = ""
62+
#if os(iOS)
63+
if isoOptions["keyShareLocation"] == nil {
64+
tokenCache = "com.microsoft.adalcache"
65+
} else {
66+
tokenCache = isoOptions["keyShareLocation"] as! String
67+
}
68+
#else
69+
if isoOptions["keyShareLocation"] == nil {
70+
tokenCache = "com.microsoft.identity.universalstorage"
71+
} else {
72+
tokenCache = isoOptions["keyShareLocation"] as! String
73+
}
74+
#endif
75+
clientConfiguration.cacheConfig.keychainSharingGroup = tokenCache
4976

50-
#if os(iOS)
51-
if isoOptions["keyShareLocation"] == nil {
52-
tokenCache = "com.microsoft.adalcache"
53-
} else {
54-
tokenCache = isoOptions["keyShareLocation"] as! String
55-
}
56-
#else
57-
if isoOptions["keyShareLocation"] == nil {
58-
tokenCache = "com.microsoft.identity.universalstorage"
59-
} else {
60-
tokenCache = isoOptions["keyShareLocation"] as! String
61-
}
62-
#endif
63-
clientConfiguration.cacheConfig.keychainSharingGroup = tokenCache
77+
6478
} else {
6579
self.msalUseBiometrics = false
6680
}
@@ -69,7 +83,6 @@ public class MsalPlugin: CAPPlugin {
6983
self.msalClient = try MSALPublicClientApplication(configuration: clientConfiguration)
7084
self.msalPopupScopes = call.getArray("scopes", String.self)
7185
self.msalHasOptions = true
72-
self.msalAuthenticated = false
7386

7487
// Step 04: Need to resolve void and send response back to the bridge
7588
call.resolve()
@@ -81,18 +94,16 @@ public class MsalPlugin: CAPPlugin {
8194
}
8295
}
8396

84-
/*
85-
86-
*/
97+
8798
@objc func acquireAccessTokenForUser(_ call: CAPPluginCall) {
88-
// Step 01: Check if Options have been set
99+
// 1. Check if Options have been set
89100
if self.msalHasOptions == false {
90101
call.reject("AcquireAccessTokenForUser Error: MSAL Plugin Options have not been set yet. Please run 'setOptions'")
91102
return
92103
}
93104

94105
if self.msalAuthenticated == true {
95-
// 1.
106+
// 2.
96107
let msalParameters = MSALParameters()
97108
msalParameters.completionBlockQueue = DispatchQueue.main
98109

@@ -102,17 +113,20 @@ public class MsalPlugin: CAPPlugin {
102113
}
103114
})
104115

105-
// 2. Validate and set scopes where passed through options
116+
// 3. Validate and set scopes where passed through options
106117
guard let tokenScopes = call.getArray("scopes", String.self) else {
107118
call.reject("AcquireAccessToken Error: No Scopes were provided")
108119
return
109120
}
110121

111-
// 3. Set Silent Token Parameters
122+
// 4. Set Silent Token Parameters
112123
let parameters = MSALSilentTokenParameters(scopes: tokenScopes, account: self.msalAccount!)
113-
parameters.forceRefresh = true
124+
if (call.getBool("forceRefresh") ?? false) == true {
125+
parameters.forceRefresh = true
126+
}
127+
114128

115-
// 4. Begin acquireing Access Token for OBO Flow and other Open ID Connect Prtocols
129+
// 5. Begin acquireing Access Token for OBO Flow and other Open ID Connect Prtocols
116130
self.msalClient?.acquireTokenSilent(with: parameters, completionBlock: { (response, error) in
117131
if let error = error {
118132
call.error("AcquireAccessToken Error: Unable to Acquire Access Token", error, [
@@ -208,7 +222,7 @@ public class MsalPlugin: CAPPlugin {
208222
if success {
209223
DispatchQueue.main.async {
210224
self.setCurrentAccount {(account) in
211-
guard let currentAccount = self.msalAccount else {
225+
guard let currentAccount = account else {
212226
self.loginInteractive(call)
213227
return
214228
}
@@ -254,6 +268,10 @@ public class MsalPlugin: CAPPlugin {
254268

255269
self.msalClient?.getCurrentAccount(with: msalParameters, completionBlock: { (currentAccount, previousAccount, error) in
256270
if let error = error {
271+
if let completion = completion {
272+
completion(nil)
273+
}
274+
257275
return
258276
}
259277

@@ -312,7 +330,8 @@ public class MsalPlugin: CAPPlugin {
312330
#endif
313331

314332
let parameters = MSALInteractiveTokenParameters(scopes: self.msalPopupScopes!, webviewParameters: webViewParameters)
315-
parameters.promptType = .selectAccount
333+
parameters.promptType = .default
334+
parameters.completionBlockQueue = DispatchQueue.main
316335

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

src/msal-capacitor-plugin/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/msal-capacitor-plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@assimalign/msal-capacitor-plugin",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "A custom Capacitor Plugin for MSAL targeting Web and IOS Platforms",
5-
"main": "dist/plugin.js",
5+
"main": "dist/index.js",
66
"module": "dist/esm/index.js",
77
"types": "dist/esm/index.d.ts",
88
"scripts": {

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

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

4243
export interface IMsalPlugin {
@@ -46,5 +47,5 @@ export interface IMsalPlugin {
4647
logout(): Promise<void>;
4748
acquireUserRoles(): Promise<{results: string[]}>;
4849
acquireAuthenticationResult(): Promise<{results: AuthenticationResult | null}>;
49-
acquireAccessTokenForUser(request?: {scopes: string[]}): Promise<{results: string}>;
50+
acquireAccessTokenForUser(request?: {scopes: string[], forceRefresh?:boolean}): Promise<{results: string}>;
5051
}

0 commit comments

Comments
 (0)