auth0 / Auth0.Android

Android toolkit for Auth0 API
https://auth0.com
MIT License
208 stars 130 forks source link

Calling WebAuthProvider start/await with context that is not an activity throws exception #743

Open joknu1 opened 1 month ago

joknu1 commented 1 month ago

Checklist

Description

This part of the SDK

        @JvmStatic
        internal fun authenticateUsingBrowser(
            context: Context,
            authorizeUri: Uri,
            launchAsTwa: Boolean,
            options: CustomTabsOptions
        ) {
            val intent = Intent(context, AuthenticationActivity::class.java)
            intent.putExtra(EXTRA_AUTHORIZE_URI, authorizeUri)
            intent.putExtra(EXTRA_LAUNCH_AS_TWA, launchAsTwa)
            intent.putExtra(EXTRA_CT_OPTIONS, options)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            context.startActivity(intent)
        }

expects context to be an activity. Otherwise AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? is thrown.

Either SDK should expect activity as parameter instead of context, or there should be a way to set what flags to use.

Reproduction

Call

            val credentials = WebAuthProvider
                .login(account)
                .withAudience(audience)
                .withScope(scope)
                .withRedirectUri(redirectUrl)
                .withParameters(parameters)
                .withCustomTabsOptions(getCustomTabsOptions())
                .await(context)

with e.g. applicationContext

Additional context

No response

Auth0.Android version

2.10.2

Android version(s)

14