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

"withFragment" does not work, I need help / a sample of how to use "withFragment" to embed MSAL login into my app #1669

Open
VansonLeung opened this issue Jan 16, 2022 · 0 comments

Comments

@VansonLeung
Copy link

VansonLeung commented Jan 16, 2022

This issue only occurs when using:

parametersBuilder.withFragment(fragment)

        var parametersBuilder = AcquireTokenParameters.Builder()
            .startAuthorizationFromActivity(activity)
            .fromAuthority(authorityUrl)
            .withScopes(scopes)
            .withPrompt(Prompt.LOGIN)
            .withCallback(acquireTokenCallback)

            parametersBuilder = parametersBuilder.withLoginHint(loginHint)
            parametersBuilder = parametersBuilder.withFragment(fragment)   // key factor of reproducing the issue
            parametersBuilder = parametersBuilder.withPrompt(msalPromptType)
            parametersBuilder = parametersBuilder.withAuthorizationQueryStringParameters(extraQueryParameters)

        val parameters = parametersBuilder.build()


        getB2CApp { b2cApp ->
            b2cApp.acquireToken(parameters)
        }

The result is that the AuthorizationActivity was "finish()"ed immediately after AuthorizationFragment runs "onCreate()"

Here's the MSAL debug log:

Performing cloud discovery Android 28
Performing cloud discovery... Android 28
Acquired lock. Android 28
Cloud discovery complete. Android 28
Cloud is known. Android 28
Use webView for authorization. Android 28
Creating AuthorizationRequestBuilder Android 28
Creating AuthorizationRequestBuilder... Android 28
Perform the authorization request with embedded webView. Android 28
No stored state. Unable to handle response Android 28
N/A Android 28
Hosting Activity is destroyed before Auth request is completed, sending request cancel Android 28
Sending result from Authorization Activity, resultCode: 2008 Android 28
Launching embedded WebView for acquiring auth code. Android 28
The start url is null Android 28
Error is returned from webview redirect Android 28

By removing:

        parametersBuilder = parametersBuilder.withFragment(fragment)

, the MSAL login works immediately

Performing cloud discovery Android 28
Performing cloud discovery... Android 28
Acquired lock. Android 28
Cloud discovery complete. Android 28
Cloud is known. Android 28
Use webView for authorization. Android 28
Creating AuthorizationRequestBuilder Android 28
Creating AuthorizationRequestBuilder... Android 28
Perform the authorization request with embedded webView. Android 28
Launching embedded WebView for acquiring auth code. Android 28
The start url is https://..........
...
...

There is NO documentation of how to actually use "withFragment" properly. I am stuck now.

@VansonLeung VansonLeung changed the title "withfragment" does not work "withFragment" does not work, I need help / a sample of how to use "withFragment" to embed MSAL login into my app Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant