跳过内容

安卓设置

在您的应用程序项目的顶级 android/build.gradle, 将 Intune Gradle 插件 JAR 添加到 buildscript classpath。该插件包包括:

  • android/ms-intune-app-sdk-android/GradlePlugin/com.microsoft.intune.mam.build.jar

另外,还包括 Ionic 文档中用于当前 Intune Android SDK 版本的 Duo Maven feed:

maven {
url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1'
name 'Duo-SDK-Feed'
}

android/app/build.gradle:

apply plugin: 'com.microsoft.intune.mam'

并保持资源优化禁用:

android.enableResourceOptimizations=false

3. 提供 auth_config.json

标题:3. 提供 auth_config.json

创建 android/app/src/main/res/raw/auth_config.json:

{
"client_id": "YOUR_CLIENT_ID",
"authorization_user_agent": "BROWSER",
"redirect_uri": "msauth://YOUR_PACKAGE/YOUR_SIGNATURE_HASH",
"broker_redirect_uri_registered": true,
"account_mode": "MULTIPLE",
"authorities": [
{
"type": "AAD",
"audience": {
"type": "AzureADMyOrg"
}
}
]
}

插件在运行时期期望该文件,用于 MSAL 和 Intune 认证回调。

4. 配置 <application> 标签 <application> 标签

如果您的应用程序尚未定义自定义

,请设置: Application复制到剪贴板

<application
android:name="app.capgo.intune.IntuneApplication"
android:enableOnBackInvokedCallback="false">

如果您已经有一个自定义 Application,扩展 MAMApplication 并注册 IntuneMamServiceAuthenticationCallbackonMAMCreate().

5. 添加代理认证查询和重定向处理

标题为“5. 添加代理认证查询和重定向处理”

添加包可见性查询 Ionic 文档:

  • com.azure.authenticator
  • com.microsoft.windowsintune.companyportal
  • 浏览器检测意图

另外添加 BrowserTabActivity 与您的 msauth:// 重定向 URI 主机/路径以便 MSAL 可以完成登录环回

应用级本地设置完成后,Capacitor API 与 iOS 相同:

import { IntuneMAM } from '@capgo/capacitor-intune';
const auth = await IntuneMAM.acquireToken({
scopes: ['https://graph.microsoft.com/.default'],
});
await IntuneMAM.registerAndEnrollAccount({
accountId: auth.accountId,
});