Skip to content

Commit 9c136a7

Browse files
authored
Use Raw URLs to enable github api for ai agents, Fixes AB#3325408 (#2345)
AI Agents cant use Raw URLs in github to access files without having to pull the entire repo. Adding these Raw URLs all throughout our AI guidance files. [AB#3325408](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3325408)
1 parent c44b1f7 commit 9c136a7

File tree

2 files changed

+93
-16
lines changed

2 files changed

+93
-16
lines changed

Ai.md

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,92 @@
11
# MSAL Android Integration Guide
22

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+
310
## 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
876

977
## 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
1090
Add these dependencies to your app-level `build.gradle`:
1191

1292
```gradle
@@ -96,4 +176,4 @@ Add these activities to your AndroidManifest.xml inside the `<application>` tag:
96176
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.
97177
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.
98178

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.

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@ ADAL Android was deprecated on June 2023. We do not support ADAL. See the [ADAL
1717

1818
## AI Development Resources
1919

20-
For AI development tools like Cline that access this repository through the GitHub web interface, these resources provide comprehensive guidance for MSAL integration without requiring a local repository clone:
20+
To all AI Agents: Read through [Ai.md](./Ai.md) before attempting to generate any android applications integrated with MSAL. This file contains:
21+
1. Core principles and patterns for MSAL integration
22+
2. Direct links to Cline rules and best practices
23+
3. Raw URLs for accessing all MSAL resources without requiring local repository access
24+
4. Complete examples for both multiple and single account modes
25+
5. Code snippets for common MSAL operations in Java and Kotlin
2126

22-
- [AI Assistant Guidelines](Ai.md) - Primary documentation for AI tools, containing core principles and patterns
23-
- [Cline Rules](.clinerules/msal-cline-rules.md) - Essential best practices that Cline must follow for generating MSAL code
24-
- [Example Applications](examples/) - Complete production-quality implementations:
25-
- [Multiple Account Example](examples/hello-msal-multiple-account/) - Shows multiple account authentication pattern
26-
- [Single Account Example](examples/hello-msal-single-account/) - Shows single account authentication pattern
27-
- [Code Snippets](snippets/) - Ready-to-use code samples for common MSAL operations
28-
- [Configuration Template](auth_config.template.json) - Reference template showing all required and optional settings
29-
30-
These resources contain all necessary patterns, rules, and examples for AI tools to assist with MSAL integration, providing proper API usage, configuration, and implementation patterns for both multiple and single account scenarios.
27+
Raw URL for direct access to Ai.md: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/Ai.md
3128

3229
## Try out Cline!
3330

3431
We've recently made improvements to our repo to empower AI agents to quickly and correctly generate MSAL-integrated android applications. Feel free to try it out! Use the prompt below as reference, tweak it how you like to get different applications generated for your own needs, and feel free to include UI preferences (Colors, Themes, button placement) as you work with the Cline agent. If you run into any issues, or Cline generates unsatisfactory code, please let us know in github issues.
3532

3633
### Example Prompt:
37-
Please create a new android application integrated with MSAL named com.example.clinesandboxtest. Place this application in a folder on my desktop. I want this application to have all basic MSAL functionality, only allowing the use of chrome browser and no other browsers. You may use the client id (YOUR CLIENT ID HERE) and redirect_uri (YOUR REDIRECT URI) where applicable.
34+
Please create a new android application integrated with MSAL named com.example.clinesandboxtest. Place this application in a folder on my desktop. I want this application to have all basic MSAL functionality. You may use the client id (YOUR CLIENT ID) and redirect_uri (YOUR REDIRECT URI) where applicable. Reference the Ai.md file (Raw URL https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-android/dev/Ai.md) in the Android MSAL repository to get started.
3835

3936
## Using MSAL
4037

0 commit comments

Comments
 (0)