Skip to content

Commit 0c601cb

Browse files
author
Simonx Xu
authored
Merge pull request #8179 from AmandaAZ/Branch-CI3607
AB#3607: Create a new article
2 parents 4377f72 + 7b52293 commit 0c601cb

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
title: Android App Authentication Fails After Being Published to Google Play Store
3+
description: Provides a solution to an authentication failure with an Android app published to the Google Play Store.
4+
ms.reviewer: markbukovich, v-weizhu
5+
ms.service: entra-id
6+
ms.date: 03/07/2025
7+
ms.custom: sap:Developing or Registering apps with Microsoft identity platform
8+
---
9+
10+
# Authentication fails after an Android app is published to the Google Play Store
11+
12+
This article provides a solution to an authentication failure that occurs during signing in after users install an Android app published to the Google Play Store.
13+
14+
## Symptoms
15+
16+
Consider the following scenario:
17+
18+
- You have successfully implemented Microsoft Entra authentication in your Android app with the Microsoft Authentication Library (MSAL).
19+
- The app has been built and executed and has passed all QA testing.
20+
- You publish the app to the Google Play Store.
21+
22+
In this case, after users install the app, authentication doesn't work when signing in to the app.
23+
24+
If you expose authentication error messages to users, or if you let them send error messages to your team, you might encounter an error message like the following text:
25+
26+
> The redirect URI in the configuration file doesn't match with the one generated with the package name and signature hash. Please verify the uri in the config file and your app registration in Azure portal.
27+
28+
Another possible scenario for this issue is:
29+
30+
During development and QA testing, you set up your app to use a supported broker to handle authentication and single sign-on (SSO). However, after the app is deployed through Google Play and installed, the app no longer uses the broker for authentication.
31+
32+
## Cause
33+
34+
When an Android application is built for installation on a device, it's built as an APK compressed package and then signed by a certificate. This certificate signing ensures that the person who built the application is the one who owns the private signing key. This prevents hackers from making harmful modifications to the application, as they can't sign their versions with the original private key.
35+
36+
Previously, Android developers owned and maintained their private signing keys. Currently, Google Play Services generates and maintains the private signing key for Android developers, ensuring secure storage by Google. The developer still maintains an upload key so that Google Play Services can verify the authenticity of an uploaded app bundle, but the actual signing is performed by the Google-owned signing certificate when users install the app on their devices.
37+
38+
The MSAL for Android Native and Microsoft Supported Authentication Brokers use the public signature hash of an installed application to identify it when interacting with the Android operating system during authentication.
39+
40+
The public signature hash of an application installed via Google Play differs from the one installed before publishing to Google Play. Thus, MSAL will be configured with the incorrect signature hash.
41+
42+
## Solution
43+
44+
To resolve this issue, do the following things:
45+
46+
- [Get a new signature hash with the MSAL Package Inspector tool or from the Google Play Console](#get-a-new-signature-hash-with-the-msal-package-inspector-tool-or-from-the-google-play-console).
47+
- [Add a new redirect URI to the app registration in the Azure portal with the new signature hash](#add-a-new-redirect-uri-to-the-app-registration-in-the-azure-portal-with-the-new-signature-hash).
48+
- [Update the MSAL configuration within the application code to use the new redirect URI and signature hash](#update-the-msal-configuration-within-the-application-code-to-use-the-new-redirect-uri-and-signature-hash).
49+
50+
### Get a new signature hash with the MSAL Package Inspector tool or from the Google Play Console
51+
52+
You can get a new signature hash by using the MSAL Package Inspector tool or from the Google Play Console.
53+
54+
To install and use the MSAL Package Inspector, see [Package Inspector for MSAL Android Native Guide](https://blogs.aaddevsup.xyz/2022/03/package-inspector-for-msal-android-native-guide/).
55+
56+
To get the signature hash from the Google Play Console, follow these steps:
57+
58+
1. Go to the Google Play Console and sign in with your Google Developer account.
59+
2. Once you're in the Google Play Console, select the affected app.
60+
3. On the left navigation, under the **Release** category, expand **Setup**, and select **App Integrity**.
61+
4. Select the **App signing** tab. You'll see the fingerprint of the app signing key in three different variations.
62+
5. Copy the **SHA-1 certificate fingerprint** and paste it into the PowerShell script in step 6 as the value of the `$Thumbprint` variable.
63+
6. Run the following script to obtain the base64 encoded fingerprint that MSAL needs:
64+
65+
```powershell
66+
$Thumbprint = "paste your fingerprint here"
67+
$Thumbprint = $Thumbprint.Replace(":", "")
68+
69+
$Bytes = [byte[]]::new($Thumbprint.Length / 2)
70+
71+
For($i=0; $i -lt $Thumbprint.Length; $i+=2){
72+
$Bytes[$i/2] = [convert]::ToByte($Thumbprint.Substring($i, 2), 16)
73+
}
74+
75+
$hashedString =[Convert]::ToBase64String($Bytes)
76+
77+
Write-Host $hashedString
78+
```
79+
80+
:::image type="content" source="media/android-app-authentication-fails-after-published-to-google-play-store/google-play-console-app-signing.png" alt-text="Screenshot that shows how to get the signature hash from the Google Play Console." lightbox="media/android-app-authentication-fails-after-published-to-google-play-store/google-play-console-app-signing.png":::
81+
82+
### Add a new redirect URI to the app registration in the Azure portal with the new signature hash
83+
84+
> [!NOTE]
85+
> We recommend adding a new redirect URI rather than modifying the existing one. Your app registration can contain many redirect URIs. Additionally, modifying the existing redirect URI might result in problems with the development version of your app. This can cause issues during troubleshooting, development updates, and so on.
86+
87+
1. Sign in to the Azure portal and navigate to the **App registrations** page.
88+
2. Select the app registration for your Android app.
89+
3. Under **Manage**, select **Authentication**.
90+
4. Under **Platform configurations**, select **Add a platform**.
91+
5. Under **Configure platforms**, select **Android**.
92+
93+
:::image type="content" source="media/android-app-authentication-fails-after-published-to-google-play-store/app-reg-platform-config.png" alt-text="Screenshot that shows how to configure the Android platform.":::
94+
6. Enter the package name of your Android app. Also, generate and enter the signature hash.
95+
96+
:::image type="content" source="media/android-app-authentication-fails-after-published-to-google-play-store/app-registrations-configure-android-app.png" alt-text="Screenshot that shows how to configure an Android app.":::
97+
98+
> [!NOTE]
99+
> It's fine to use the same package name in multiple Android redirect URIs as long as the signature hash is different.
100+
7. Select **Configure** to complete the platform configuration.
101+
102+
### Update the MSAL configuration within the application code to use the new redirect URI and signature hash
103+
104+
Update the MSAL configuration file and Android Manifest file in the application code.
105+
106+
- MSAL configuration file:
107+
108+
Only change the redirect URI. Copy and paste it directly from the Azure portal. In the Azure portal, the signature hash portion of the redirect URI is HTTP encoded. It should remain HTTP encoded.
109+
110+
```json
111+
{
112+
"client_id": "<Client ID>",
113+
"authorization_user_agent": "DEFAULT",
114+
"redirect_uri": "<Redirect URI>"
115+
"broker_redirect_uri_registered": true,
116+
"authorities": [
117+
{
118+
"types": "AAD",
119+
"audience": {
120+
"type": "AzureADMyOrg",
121+
"tenant_id": "<Tenant ID>"
122+
}
123+
}
124+
],
125+
"logging":{
126+
"log_level": "VERBOSE",
127+
"logcat_enabled": true
128+
}
129+
}
130+
```
131+
132+
- Android Manifest file:
133+
134+
Only change the `android:path` property in the `com.microsoft.identity.client.BrowserTabActivity` activity. Paste the signature hash as the value of this property.
135+
136+
```xml
137+
<activity
138+
android:name="com.microsoft.identity.client.BrowserTabActivity">
139+
<intent-filter>
140+
<action android:name="android.intent.action.VIEW" />
141+
<category android:name="android.intent.category.DEFAULT" />
142+
<category android:name="android.intent.category.BROWSABLE" />
143+
<data
144+
android:schema="msauth"
145+
android:host="com.example.azureauthsso1"
146+
android:path="android_path" />
147+
</intent-filter>
148+
</activity>
149+
```
150+
151+
152+
> [!NOTE]
153+
> - Make sure to include the forward slash in front of the signature hash.
154+
> - Unlike the redirect URI, the signature hash here isn't HTTP encoded.
155+
156+
[!INCLUDE [Third-party information disclaimer](../../../includes/third-party-disclaimer.md)]
157+
158+
[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)]
Loading
Loading
Loading

support/entra/entra-id/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@
5151
items:
5252
- name: IDX10501 Error in ASP.NET Core with Azure B2C Custom Policy
5353
href: app-integration/troubleshoot-error-idx10501-aspnet-b2c.md
54+
- name: Authentication fails after Android app is published to Google Play Store
55+
href: app-integration/android-app-authentication-fails-after-published-to-google-play-store.md
5456
- name: WIF10201 No valid key mapping found
5557
href: app-integration/troubleshoot-wif10201-no-validkey-securitytoken-mvc.md
5658

59+
5760
- name: Troubleshoot adding apps
5861
href: app-integration/troubleshoot-adding-apps.md
5962
items:

0 commit comments

Comments
 (0)