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

Android 14 Breaks OAuth2 Redirect #973

Closed
4 tasks done
kelsonflint opened this issue Jun 9, 2023 · 2 comments
Closed
4 tasks done

Android 14 Breaks OAuth2 Redirect #973

kelsonflint opened this issue Jun 9, 2023 · 2 comments
Labels

Comments

@kelsonflint
Copy link

Checklist:

Configuration

  • Version: 0.1.11
  • Integration: Native - Kotlin

Issue Description

Hi there. Since upgrading to the Android 14 Beta 3 (API 34), the OAuth2 Redirect URI always comes out to be null, resulting in the AuthorizationManagementActivity's onResume() to return RESULT_CANCELED. The existing code works for Android 13 and below, and the newest Android release might be introducing a breaking change. Any help would be appreciated, as the full release of Android 14 is expected in August/September.

Here is the code where I launch the RedriectUriReceiverActivity:

private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
        if (result.data == null || result.resultCode == RESULT_CANCELED) {
            // handle failure
        } else if (result.resultCode == RESULT_OK) {
            val authResp = AuthorizationResponse.fromIntent(result.data!!)
            val authEx = AuthorizationException.fromIntent(result.data)
            // do stuff
        }
    }


private fun launchBrowserForAuth() {
    val authStateSyncHelper = serviceLocator.authStateSyncHelper
    val authorizationService = AuthorizationService(
        serviceLocator.context,
        AppAuthConfiguration.Builder()
            .setBrowserMatcher(generateBrowserAllowList())
            .build()
    )
    val serviceConfig = AuthorizationServiceConfiguration(
        Uri.parse(BuildConfig.PROVIDER_URL), // authorization endpoint
        Uri.parse(BuildConfig.TOKEN_URL)
    ) // token endpoint
    authStateSyncHelper.replace(AuthState(serviceConfig))
    val authRequest = AuthorizationRequest.Builder(
        serviceConfig, // the authorization service configuration
        BuildConfig.CLIENT_ID, // the client ID, typically pre-registered and static
        ResponseTypeValues.CODE, // the response_type value: we want a code
        Uri.parse(BuildConfig.OAUTH_REDIRECT_URI)
    ) // the redirect URI to which the auth response is sent
        .setScope(BuildConfig.SCOPE)
        .build()

    val authIntent = authorizationService.getAuthorizationRequestIntent(
        authRequest
    )

    resultLauncher.launch(authIntent)
}
@kelsonflint kelsonflint added the bug label Jun 9, 2023
@agologan
Copy link
Collaborator

Have tested the demo app in both beta3 and now beta4 with both custom schema and AppLink and haven't noticed anything new.

There may be issue as we've seen with Android 12 where the activity was being recreated #769 but we need some further information on the observed lifecycle to understand it.

@kelsonflint
Copy link
Author

Thanks @agologan
Issue was resolved by defining the AuthorizationManagementActivity as a SingleInstance with help from #977
<activity android:name=".AuthorizationManagementActivity" android:exported="false" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden" android:theme="@style/Theme.AppCompat.Translucent.NoTitleBar" android:launchMode="singleInstance" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants