Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InteractiveBrowserCredential not working in Android #2160

Closed
diyoyo opened this issue Sep 16, 2024 · 1 comment
Closed

InteractiveBrowserCredential not working in Android #2160

diyoyo opened this issue Sep 16, 2024 · 1 comment
Labels
area:documentation Focused on documentation of the product type:bug A broken experience

Comments

@diyoyo
Copy link

diyoyo commented Sep 16, 2024

Describe the bug

Description

I tried following the setup tutorial, picking the InteractiveBrowserCredential, but running everything on Android. Yet, the browser does not work and this code makes the app crash

        new Thread(()->{
            final InteractiveBrowserCredential credential = new InteractiveBrowserCredentialBuilder()
                    .clientId(CLIENT_ID)
                    .tenantId(TENANT_ID)
                    .redirectUrl("http://localhost")
                    .build();


            if (null == scopes || null == credential) {
                print("Unexpected error");
            }

//        final AzureIdentityAuthenticationProvider authenticationProvider =
//                new AzureIdentityAuthenticationProvider(credential, null, scopes);
//
//        mClient = new GraphServiceClient(authenticationProvider);

           mClient = new GraphServiceClient(credential, scopes);

            print(mClient.me().get().getAboutMe());

        }).start();

StackTrace

The error seems to relate to the HttpClient:

        com.azure.core.exception.ClientAuthenticationException: Failed to acquire token with Interactive Browser Authentication.
                                                                                                    	at com.azure.identity.implementation.IdentitySyncClient.authenticateWithBrowserInteraction(IdentitySyncClient.java:336)
                                                                                                    	at com.azure.identity.InteractiveBrowserCredential.getTokenSync(InteractiveBrowserCredential.java:174)
                                                                                                    	at com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider.getAuthorizationToken(AzureIdentityAccessTokenProvider.java:167)
                                                                                                    	at com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider.authenticateRequest(BaseBearerTokenAuthenticationProvider.java:46)
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:711)
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:276)
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:761)
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:747)

...

                            Caused by: java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/sun/net/httpserver/HttpHandler;
                                                                                                    	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:372)
                                                                                                    	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2049)
                                                                                                    	at com.azure.identity.implementation.IdentitySyncClient.authenticateWithBrowserInteraction(IdentitySyncClient.java:334)
                                                                                                    	at com.azure.identity.InteractiveBrowserCredential.getTokenSync(InteractiveBrowserCredential.java:174) 
                                                                                                    	at com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider.getAuthorizationToken(AzureIdentityAccessTokenProvider.java:167) 
                                                                                                    	at com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider.authenticateRequest(BaseBearerTokenAuthenticationProvider.java:46) 
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:711) 
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:276) 
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:761) 
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:747) 
                                                                                                    	at 
                                                                                                    Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/sun/net/httpserver/HttpHandler;
                                                                                                    	at com.microsoft.aad.msal4j.AbstractClientApplicationBase.getAuthenticationResultSupplier(AbstractClientApplicationBase.java:146)
                                                                                                    	at com.microsoft.aad.msal4j.AbstractClientApplicationBase.executeRequest(AbstractClientApplicationBase.java:118)
                                                                                                    	at com.microsoft.aad.msal4j.PublicClientApplication.acquireToken(PublicClientApplication.java:130)
                                                                                                    	at com.azure.identity.implementation.IdentitySyncClient.authenticateWithBrowserInteraction(IdentitySyncClient.java:334) 
                                                                                                    	at com.azure.identity.InteractiveBrowserCredential.getTokenSync(InteractiveBrowserCredential.java:174) 
                                                                                                    	at com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider.getAuthorizationToken(AzureIdentityAccessTokenProvider.java:167) 
                                                                                                    	at com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider.authenticateRequest(BaseBearerTokenAuthenticationProvider.java:46) 
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:711) 
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:276) 
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:761) 
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:747) 
                                                                                                    	at 
                                                                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.net.httpserver.HttpHandler" on path: DexPathList[[dex file com.microsoft.aad.msal4j.AbstractClientApplicationBase.getAuthenticationResultSupplier(AbstractClientApplicationBase.java:146) 
                                                                                                    	at com.microsoft.aad.msal4j.AbstractClientApplicationBase.executeRequest(AbstractClientApplicationBase.java:118) 
                                                                                                    	at com.microsoft.aad.msal4j.PublicClientApplication.acquireToken(PublicClientApplication.java:130) 
                                                                                                    	at com.azure.identity.implementation.IdentitySyncClient.authenticateWithBrowserInteraction(IdentitySyncClient.java:334) 
                                                                                                    	at com.azure.identity.InteractiveBrowserCredential.getTokenSync(InteractiveBrowserCredential.java:174) 
                                                                                                    	at com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider.getAuthorizationToken(AzureIdentityAccessTokenProvider.java:167) 
                                                                                                    	at com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider.authenticateRequest(BaseBearerTokenAuthenticationProvider.java:46) 
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.getHttpResponseMessage(OkHttpRequestAdapter.java:711) 
                                                                                                    	at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:276) 
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:761) 
                                                                                                    	at com.microsoft.graph.users.item.UserItemRequestBuilder.get(UserItemRequestBuilder.java:747) 
                                                                                                    	at 

What I tried

  • adding useLibrary 'org.apache.http.legacy' to my gradle.build file
  • adding <uses-library android:name="org.apache.http.legacy" android:required="true" /> to the AndroidManifest.xml file

It simply doesn't work.

Expected behavior

I tried it on my desktop, using a minimalist Java app and pasting the code in public static void main() and got the following behavior:

  • browser opens at login page
  • after login, page reads "you can close this window"
  • then the System.out actually prints the user's info.

I expected the same on Android.

How to reproduce

copy paste the code above.

SDK Version

6.16.0

Latest version known to work for scenario above?

No response

Known Workarounds

Well, giving up on the msgraph-sdk-java, using the code generated on entra.microsoft.com for signing in and making my own GraphHelper class to send raw API calls rather than using the SDK

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@diyoyo diyoyo added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Sep 16, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Sep 19, 2024

Thank you for reporting this @diyoyo.

Unfortunately, the Azure SDK for Android doesn't have a production identity package that would provide the right TokenCredential objects that you would easily pass to the GraphServiceClient & the Azure Identity Java SDK doesn't support Android. We would need to update the sample with some hacks to get this working. Please bear with us on this.

We'll track this work under this similar issue.

@Ndiritu Ndiritu closed this as completed Sep 19, 2024
@Ndiritu Ndiritu added area:documentation Focused on documentation of the product type:enhancement Enhancement request targeting an existing experience and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:enhancement Enhancement request targeting an existing experience labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:documentation Focused on documentation of the product type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants