|
1 | 1 | # MSAL Android Integration Guide |
2 | 2 |
|
| 3 | +Use this as the starting point for all AI Agents looking to create an Android application integrated with MSAL. |
| 4 | + |
| 5 | +## Rules Files |
| 6 | +- [Cline Rules](./.clinerules/msal-cline-rules.md) - Detailed rules and requirements for AI assistants generating MSAL-integrated applications |
| 7 | +- Raw URLs for direct access: |
| 8 | + - Cline Rules: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/.clinerules/msal-cline-rules.md |
| 9 | + |
3 | 10 | ## AI-Friendly Directories |
4 | | -- [Multiple Account Mode Sample](./examples/hello-msal-multiple-account/) - Use this when you want to support multiple accounts in your application (default mode) |
5 | | -- [Single Account Mode Sample](./examples/hello-msal-single-account/) - Use this when you want to support single account authentication only |
6 | | -- [Configuration Template](./auth_config.template.json) - Configuration template containing explanation of MSAL configuration settings and their default values |
7 | | -- [Code Snippets](./snippets/) - Code snippets showing how to use the MSAL APIs in Java and Kotlin for multiple and single acount modes. |
| 11 | +The following directories contain essential resources for generating MSAL-integrated Android applications. Each entry includes both the repository path and a direct raw URL for access without requiring local repository access. |
| 12 | + |
| 13 | +### Multiple Account Mode Sample |
| 14 | +Use this when generating a multiple-account mode application (default mode). If the user does not specify an account mode, assume they want multiple-account mode. |
| 15 | +- Repository Path: [./examples/hello-msal-multiple-account/](./examples/hello-msal-multiple-account/) |
| 16 | +- Required Files: |
| 17 | + - Gradle Files: |
| 18 | + - build.gradle: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/build.gradle |
| 19 | + - gradle.properties: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/gradle.properties |
| 20 | + - settings.gradle: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/settings.gradle |
| 21 | + - app/build.gradle: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/app/build.gradle |
| 22 | + |
| 23 | + - Essential Source Files: |
| 24 | + - AndroidManifest.xml: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/app/src/main/AndroidManifest.xml |
| 25 | + - auth_config.json: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/app/src/main/res/raw/auth_config.json |
| 26 | + - MainActivity.java: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/app/src/main/java/com/example/msalmultipleaccount/MainActivity.java |
| 27 | + - AuthHelper.java: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/app/src/main/java/com/example/msalmultipleaccount/AuthHelper.java |
| 28 | + - GraphHelper.java: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-multiple-account/app/src/main/java/com/example/msalmultipleaccount/GraphHelper.java |
| 29 | + |
| 30 | +### Single Account Mode Sample |
| 31 | +Use this when generating a single-account mode application. |
| 32 | +- Repository Path: [./examples/hello-msal-single-account/](./examples/hello-msal-single-account/) |
| 33 | +- Required Files: |
| 34 | + - Gradle Files: |
| 35 | + - build.gradle: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/build.gradle |
| 36 | + - gradle.properties: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/gradle.properties |
| 37 | + - settings.gradle: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/settings.gradle |
| 38 | + - app/build.gradle: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/app/build.gradle |
| 39 | + |
| 40 | + - Essential Source Files: |
| 41 | + - AndroidManifest.xml: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/app/src/main/AndroidManifest.xml |
| 42 | + - auth_config.json: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/app/src/main/res/raw/auth_config.json |
| 43 | + - MainActivity.java: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/app/src/main/java/com/example/msalsingleaccount/MainActivity.java |
| 44 | + - AuthHelper.java: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/app/src/main/java/com/example/msalsingleaccount/AuthHelper.java |
| 45 | + - GraphHelper.java: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/examples/hello-msal-single-account/app/src/main/java/com/example/msalsingleaccount/GraphHelper.java |
| 46 | + |
| 47 | +### Configuration Template |
| 48 | +Configuration template containing MSAL configuration settings and their default values. |
| 49 | +- Repository Path: [./auth_config.template.json](./auth_config.template.json) |
| 50 | +- Raw URL: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/auth_config.template.json |
| 51 | + |
| 52 | +### Code Snippets |
| 53 | +Sample files demonstrating MSAL API usage in both Java and Kotlin. |
| 54 | +- Repository Path: [./snippets/](./snippets/) |
| 55 | +- Java: |
| 56 | + - MSAL Initialization: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/msal_initialization.java |
| 57 | + - Acquire Token: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/acquire_token.java |
| 58 | + - Acquire Token Silent: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/acquire_token_silent.java |
| 59 | + - Sign In: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/sign_in.java |
| 60 | + - Sign In Again: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/sign_in_again.java |
| 61 | + - Sign Out: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/sign_out_account.java |
| 62 | + - Get Accounts: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/get_accounts.java |
| 63 | + - Get Current Account: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/get_current_account.java |
| 64 | + - Remove Account: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/remove_account.java |
| 65 | + |
| 66 | +- Kotlin: |
| 67 | + - MSAL Initialization: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/msal_initialization.kt |
| 68 | + - Acquire Token: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/acquire_token.kt |
| 69 | + - Acquire Token Silent: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/acquire_token_silent.kt |
| 70 | + - Sign In: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/sign_in.kt |
| 71 | + - Sign In Again: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/sign_in_again.kt |
| 72 | + - Sign Out: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/sign_out_account.kt |
| 73 | + - Get Accounts: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/get_accounts.kt |
| 74 | + - Get Current Account: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/get_current_account.kt |
| 75 | + - Remove Account: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/snippets/remove_account.kt |
8 | 76 |
|
9 | 77 | ## Required Dependencies |
| 78 | + |
| 79 | +### Enable AndroidX Support |
| 80 | +MSAL requires AndroidX support libraries. In your project's gradle.properties file, ensure AndroidX is enabled: |
| 81 | +```properties |
| 82 | +# Required for MSAL - Enable AndroidX and Jetifier |
| 83 | +android.useAndroidX=true |
| 84 | +android.enableJetifier=true |
| 85 | +``` |
| 86 | + |
| 87 | +Note: Without these properties, the application will fail to compile as MSAL and its dependencies use AndroidX libraries. |
| 88 | + |
| 89 | +### App-level Dependencies |
10 | 90 | Add these dependencies to your app-level `build.gradle`: |
11 | 91 |
|
12 | 92 | ```gradle |
@@ -96,4 +176,4 @@ Add these activities to your AndroidManifest.xml inside the `<application>` tag: |
96 | 176 | 4. Broker integration (Microsoft Authenticator, Company Portal, or Link To Windows) is strongly recommended and should always be enabled for enhanced security and SSO capabilities. Only disable broker integration if explicitly required by the user. See broker_redirect_uri_registered field in [auth_config.template.json](./auth_config.template.json) for configuration. |
97 | 177 | 5. Device Code Flow is not recommended due to security concerns in the industry. The AcquireToken authentication method should be used instead. There are some niche scenarios where some devices lack the input methods necessary for AcquireToken, and need to use AcquireTokenWithDeviceCode. |
98 | 178 |
|
99 | | -For full implementation details, refer to the golden path example apps linked above. |
| 179 | +For full implementation details, refer to `hello-msal-multiple-account` and `hello-msal-single-account` linked above. |
0 commit comments