Skip to content

Instantly share code, notes, and snippets.

@johan12345
Last active May 9, 2025 05:56
Show Gist options
  • Save johan12345/7e2a0373a076ce72adec0e380e462e92 to your computer and use it in GitHub Desktop.
Save johan12345/7e2a0373a076ce72adec0e380e462e92 to your computer and use it in GitHub Desktop.
Modify MS Teams Android app to use different User-Agent on login page

How to modify the MS Teams Android app to use a different User-Agent on its login page

Tools needed

Instructions

  1. Get the APK of the current MS Teams app (e.g. by copying it from your phone or downloading from APKMirror). These instructions were tested with version 1416/1.0.0.2022394701, and assume it is saved as teams.apk.

  2. Extract the APK:

     apktool -r d teams.apk
    
  3. Find the WebViewAuthorizationFragment class. In the current version it is under smali_classes3/com/microsoft/identity/common/internal/providers/oauth2/WebViewAuthorizationFragment.smali.

  4. In this class, in the setUpWebView function, the User-Agent for the WebView is set like this:

     invoke-virtual {v0, p1}, Landroid/webkit/WebSettings;->setUserAgentString(Ljava/lang/String;)V
    

    Right before this, add the following line to override the User-Agent:

     const-string p1, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
    

    (or another recent desktop User-Agent)

  5. In the res/raw directory, in each of the files msal_config.json, msal_config_opt_disabled.json, msal_enterprise_config.json and msal_enterprise_config_opt_disabled.json, set the broker_redirect_uri_registered setting to false. This is needed because the modified APK will be signed with a different key. This seems to be no longer necessary in the newest version of the Teams app. Yay! 🥳

  6. Rebuild the APK:

     apktool b teams -o teams_mod.apk
    

    If you need to install the app alongside the official Teams app, change the package name now and rename conflicting content providers in the Manifest (e.g. using this tool):

     git clone [email protected]:johan12345/ApkRename.git
     ApkRename/apkRename.sh teams_mod.apk com.microsoft.teams.mod!
    
  7. Zipalign:

     zipalign -f -p 4 teams_mod.apk teams_mod_zipalign.apk
    
  8. Sign the APK:

     keytool -genkey -keystore keys.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias Teams
     apksigner sign --ks keys.keystore  --out teams_mod_signed.apk teams_mod_zipalign.apk
    
  9. Install the resulting teams_mod_signed.apk on your Android device. If you did not change the package name above, you will need to uninstall the official version of Teams first due to the different signature.

@johan12345
Copy link
Author

johan12345 commented Nov 17, 2024

crashing after email address introduction when selcting work ors school account with message: Sorry, but we're having trouble signing you in, please try again.

Well, that is not a crash, just an error message from Microsoft - so likely your company's MS sign-in page does not like the modified Teams app. In my company's case, it would directly redirect to the company's own sign-in page after entering the email address (and that just identifies mobile devices based on their User-Agent), so maybe that is why I haven't encountered this? 🤔

@colyro
Copy link

colyro commented Nov 18, 2024

oh I forgot to mention, I did not modify/alter anything especially to see if this is happening only if I touch the original apk.
I just decompiled original apk, recompiled, zipaling and sign.

So it is due to original apk manipulation

@veganvelociraptor
Copy link

I share the same issue as @colyro. On my Android 13 phone, the app just quits less than a second after starting it if I change the user agent. I tried several user agents in case that would make any difference, but nope.

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment