AzureAD / microsoft-authentication-library-common-for-android

Common code used by both the Active Directory Authentication Library (ADAL) and the Microsoft Authentication Library (MSAL)
MIT License
41 stars 35 forks source link

Handle repeated camera requests. #2332

Closed p3dr0rv closed 8 months ago

p3dr0rv commented 8 months ago

Why?

There is a strange behavior in Android where we have recurring permission requests.

See:

2024-02-26 17:21:15.200 15913-15934 WebViewAut...nchWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:15 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Launching embedded WebView for acquiring auth code.
2024-02-26 17:21:15.201 15913-15934 WebViewAut...nchWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:15 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] The start url is https://login.windows-ppe.net/common/oAuth2/v2.0/authorize?prompt=login&client-request-id=b641dde5-a42e-4a44-88bd-8dcfb99839b8&x-client-CPU=arm64-v8a&x-client-DM=SM-F926U1&x-client-OS=34&x-client-SKU=MSAL.Android&x-client-Ver=5.1.0&login_hint=&instance_aware=true&code_challenge=w5xXUWJzvbQJiVQ7mUQKmkyc_lnvr5NFHRItY17gB1I&code_challenge_method=S256&pc=18&client_id=29d9ed98-a469-4536-ade2-f981bc1d605e&redirect_uri=msauth%3A%2F%2FMicrosoft.AAD.BrokerPlugin&response_type=code&scope=aza+openid+email+profile+offline_access+urn%3Aaad%3Atb%3Aupdate%3Aprt%2F.default&state=MTA2OmIxOWI0OWUxLThiMTktNDkyOS1iNjgxLTNkMTA3ZjA4Y2I3Yy00NmNmMTBkZi04OTZhLTQzNWYtODUwMS04MjU1NTkyYmJhMzQ&brkr=1&x-client-brkrver=13.1.1&x-app-name=com.msft.identity.client.sample.local&x-app-ver=1.0-local&caller_app_client_id=29d9ed98-a469-4536-ade2-f981bc1d605e&caller_app_redirect_uri=msauth%3A%2F%2Fcom.msft.identity.client.sample.local%2F1wIqXSqBj7w%252Bh11ZifsnqwgyKrY%253D&prt_protocol_version=3.0
2024-02-26 17:21:17.797 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:17 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:17.798 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:17 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] New camera request.
2024-02-26 17:21:17.802 15913-15934 WebViewAut...onFromUser com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:17 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Requesting camera permission.
2024-02-26 17:21:20.096 15913-15934 WebViewAut...onFragment com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Camera permission granted: false
2024-02-26 17:21:20.211 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:20.213 15913-15934 WebViewAut...edRequests com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Repeated request, denying the permission
2024-02-26 17:21:20.292 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:20.292 15913-15934 WebViewAut...edRequests com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Repeated request, denying the permission
2024-02-26 17:21:20.375 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:20.376 15913-15934 WebViewAut...edRequests com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Repeated request, denying the permission
2024-02-26 17:21:20.466 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:20.468 15913-15934 WebViewAut...edRequests com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Repeated request, denying the permission
2024-02-26 17:21:20.556 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:20.556 15913-15934 WebViewAut...edRequests com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:20 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Repeated request, denying the permission
2024-02-26 17:21:35.057 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:35 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:35.058 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:35 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] New camera request.
2024-02-26 17:21:35.059 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:35 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Show camera rationale.
2024-02-26 17:21:38.507 15913-15934 WebViewAut...onFromUser com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:38 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Requesting camera permission.
2024-02-26 17:21:40.257 15913-15934 WebViewAut...onFragment com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:40 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Camera permission granted: true
2024-02-26 17:21:41.434 15913-15934 WebViewAut...tUpWebView com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:41 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Permission requested from:https://login.windows-ppe.net/ for resources:[android.webkit.resource.VIDEO_CAPTURE]
2024-02-26 17:21:41.436 15913-15934 WebViewAut...edRequests com.microsoft.identity.testuserapp   I  [2024-02-27 01:21:41 - thread_id: 2, correlation_id: b641dde5-a42e-4a44-88bd-8dcfb99839b8 - Android 34] Repeated request, granting the permission.

What changed?

To handle this, we added a check to see if this request is new or if we had already resolved it. If this has already been resolved in the past, we simply grant or deny it based on the current status. If it is a new request, we proceed with the user.

Test performed. https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2854926 https://identitydivision.visualstudio.com/Engineering/_workitems/edit/2854908