@@ -7,6 +7,10 @@ import android.net.Uri
77import android.os.Bundle
88import androidx.annotation.VisibleForTesting
99import com.auth0.android.authentication.AuthenticationException
10+ import com.auth0.android.authentication.AuthenticationException.Companion.ERROR_KEY_CT_OPTIONS_NULL
11+ import com.auth0.android.authentication.AuthenticationException.Companion.ERROR_KEY_URI_NULL
12+ import com.auth0.android.authentication.AuthenticationException.Companion.ERROR_VALUE_AUTHORIZE_URI_INVALID
13+ import com.auth0.android.authentication.AuthenticationException.Companion.ERROR_VALUE_CT_OPTIONS_INVALID
1014import com.auth0.android.callback.RunnableTask
1115import com.auth0.android.provider.WebAuthProvider.failure
1216import com.auth0.android.provider.WebAuthProvider.resume
@@ -68,23 +72,44 @@ public open class AuthenticationActivity : Activity() {
6872 }
6973
7074 private fun launchAuthenticationIntent () {
71- val extras = intent.extras
72- val authorizeUri = extras!! .getParcelable<Uri >(EXTRA_AUTHORIZE_URI )
73- val customTabsOptions: CustomTabsOptions = extras.getParcelable(EXTRA_CT_OPTIONS )!!
75+ val extras: Bundle ? = intent.extras
76+
77+ val authorizeUri = extras?.getParcelable<Uri >(EXTRA_AUTHORIZE_URI )
78+ authorizeUri ? : run {
79+ deliverAuthenticationFailure(
80+ AuthenticationException (
81+ ERROR_KEY_URI_NULL , ERROR_VALUE_AUTHORIZE_URI_INVALID
82+ )
83+ )
84+ return
85+ }
86+
87+ val customTabsOptions: CustomTabsOptions ? = extras.getParcelable(EXTRA_CT_OPTIONS )
88+ customTabsOptions ? : run {
89+ deliverAuthenticationFailure(
90+ AuthenticationException (
91+ ERROR_KEY_CT_OPTIONS_NULL , ERROR_VALUE_CT_OPTIONS_INVALID
92+ )
93+ )
94+ return
95+ }
96+
7497 val launchAsTwa: Boolean = extras.getBoolean(EXTRA_LAUNCH_AS_TWA , false )
7598 customTabsController = createCustomTabsController(this , customTabsOptions)
7699 customTabsController!! .bindService()
77- customTabsController!! .launchUri(authorizeUri!! , launchAsTwa, getInstance(), object : RunnableTask <AuthenticationException > {
78- override fun apply (error : AuthenticationException ) {
79- deliverAuthenticationFailure(error)
80- }
81- })
100+ customTabsController!! .launchUri(authorizeUri,
101+ launchAsTwa,
102+ getInstance(),
103+ object : RunnableTask <AuthenticationException > {
104+ override fun apply (error : AuthenticationException ) {
105+ deliverAuthenticationFailure(error)
106+ }
107+ })
82108 }
83109
84110 @VisibleForTesting(otherwise = VisibleForTesting .PRIVATE )
85111 internal open fun createCustomTabsController (
86- context : Context ,
87- options : CustomTabsOptions
112+ context : Context , options : CustomTabsOptions
88113 ): CustomTabsController {
89114 return CustomTabsController (context, options, TwaLauncher (context))
90115 }
@@ -107,10 +132,7 @@ public open class AuthenticationActivity : Activity() {
107132
108133 @JvmStatic
109134 internal fun authenticateUsingBrowser (
110- context : Context ,
111- authorizeUri : Uri ,
112- launchAsTwa : Boolean ,
113- options : CustomTabsOptions
135+ context : Context , authorizeUri : Uri , launchAsTwa : Boolean , options : CustomTabsOptions
114136 ) {
115137 val intent = Intent (context, AuthenticationActivity ::class .java)
116138 intent.putExtra(EXTRA_AUTHORIZE_URI , authorizeUri)
0 commit comments