Skip to content

Instantly share code, notes, and snippets.

@johan12345
Last active August 26, 2023 06:40
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 git@github.com: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 -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.

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