okta-react-native icon indicating copy to clipboard operation
okta-react-native copied to clipboard

signInWithBrowser() does not open browser in Android

Open nassimerrahoui opened this issue 1 year ago • 8 comments

Describe the bug?

signInWithBrowser() does not open browser in Android without any error.

What is expected to happen?

Open browser to signIn in okta hosted widget.

What is the actual behavior?

When I launch my react native app, then click on signInWithBrowser() then nothing happen.

And my config is correct and it's displayed.

Reproduction Steps?

Create a React Native App with Expo and Typescript. Then, install okta react native dependency Then configure your okta oidc config with correct information like:

  • clientId
  • redirectUri
  • endSessionRedirectUri
  • discoveryUri
  • scopes
  • requireHardwareBackedKeyStore: false

Then call createConfig with that configuration in App.tsx

Then call signInWithBrowser

Additional Information?

No response

SDK Version

@okta/okta-react-native: 2.12.0

Build Information

No response

nassimerrahoui avatar May 06 '24 20:05 nassimerrahoui

Hi @nassimerrahoui, thanks for filing this bug. I will look into this soon and provide relevant updates on this issue.

rajdeepnanua-okta avatar May 09 '24 14:05 rajdeepnanua-okta

It is working now on IOS. But in Android, signInWithBrowser does not open browser even if i added this in app's build.gradle

        manifestPlaceholders = [
            appAuthRedirectScheme: "com.myapp.name"
        ]
...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
...

    implementation("com.okta.android:okta-oidc-android:1.3.4")
    implementation("androidx.browser:browser:1.5.0")

nassimerrahoui avatar Jun 26 '24 21:06 nassimerrahoui

I tested with an empty projet and it works, maybe it's a wrong configuration, I'll keep you informed of the cause.

nassimerrahoui avatar Jun 27 '24 11:06 nassimerrahoui

I tested with an empty projet and it works, maybe it's a wrong configuration, I'll keep you informed of the cause.

Can you inform us of the issue? @nassimerrahoui

Justicea83 avatar Jul 27 '24 22:07 Justicea83

Solution which works for me :

In Android folder built and build.gradle from app folder :

    defaultConfig {
        ...
        manifestPlaceholders = [
            appAuthRedirectScheme: 'my.redirect.uri'
        ]
    }

    ...

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

    ...

    dependencies {
        ...
        implementation 'com.okta.android:okta-oidc-android:1.3.4'
        ...
    }

Then in createConfig use requireHardwareBackedKeyStore: false

Important point : Be careful with useEffects, which can also hinder the opening of the Okta page.

nassimerrahoui avatar Aug 12 '24 09:08 nassimerrahoui

Will try this config out and give my updates

Justicea83 avatar Aug 12 '24 14:08 Justicea83

For those who are not able to open browser in android, the value for the appAuthRedirectScheme should be the app id you used as the redirect uri before :/.

For example if your redirect uri is - com.example.app:/callback and logout uri maybe com.example.app:/logout

Then you need to use appAuthRedirectScheme: 'com.example.app' Thats it. its working but no one mentioned clearly what you need to put here. Some guide from pusher says put company name id and above comment says you put redirect uri.. so people might use the full redirect uri.. thats why posting this comment for clarification.

Thanks.

mahesh-ivy avatar Sep 03 '24 12:09 mahesh-ivy

This worked for me. After researching for almost 2 weeks I realized my scheme was http:

Add this to you Android.manifest file:

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" />
                <data android:host="${appAuthRedirectScheme}" />
                <data android:pathPrefix="/callback" />
            </intent-filter>

This works if your scheme is http

Justicea83 avatar Sep 03 '24 17:09 Justicea83