This plugin enables MSAL support for Capacitor.
npm install @velocitycubed/capacitor-plugin-msauth-v2yarn add @recognizebv/capacitor-plugin-msauth
npx cap sync
AndroidManifest.xml.
com.microsoft.adalcache
Info.plist file:
CFBundleURLTypes
CFBundleURLSchemes
msauth.$(PRODUCT_BUNDLE_IDENTIFIER)
LSApplicationQueriesSchemes
msauthv2
msauthv3
`
* (iOS) Add import RecognizebvCapacitorPluginMsauth to the top of the AppDelegate file to ensure that the library is linked
* (iOS) if your app's AppDelegate already implements a application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool function, you should add the following code inside this method:
`swift
if MsAuthPlugin.checkAppOpen(url: url, options: options) == true {
return true
}
`
* (Android) In the AndroidManifest.xml file, append the following code within the section:
`xml
android:name="com.microsoft.identity.client.BrowserTabActivity"
android:exported="true">
android:host=""
android:path="/" />
`
Note that there are two placeholders, one for you package name and one for the key hash.
* (Android) Add the following snippet to the build.gradle file in the android/ folder
`gradle
allprojects {
repositories {
maven {
url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1'
}
}
}
`
* (Android) Register the plugin in the main activity
Usage
Usage of the plugin is fairly simple, as it has just two methods: login and logout.
$3
`typescript
import {Plugins} from '@capacitor/core';
const {MsAuthPlugin} = Plugins;
const result = await MsAuthPlugin.login({
clientId: '',
tenant: '',
domainHint: '',
scopes: [''],
keyHash: '',
authorityType: '',
authorityUrl: '',
});
const accessToken = result.accessToken;
`
$3
`typescript
import {Plugins} from '@capacitor/core';
const {MsAuthPlugin} = Plugins;
await MsAuthPlugin.logout({
clientId: '',
tenant: '',
domainHint: '',
keyHash: '',
});
`
MSAL Versions
There are some scenarios where the default project may be generated in such a way which prevents a build from succeeding. To get around this, a variable has been exposed to allow users to configure the Microsoft Authentication library version. By setting the recognizebvMSALVersion variable in your root build.gradle you can override the default version used during dependency resolution. See this issue for more details. Here's an example you can place in your root build.gradle file to override the MSAL version.
`groovy
ext {
recognizebvMSALVersion = '5.3.0' // This version fixed the open telemetry issue described in issue #42.
}
``