okta-react-native
okta-react-native copied to clipboard
signInWithBrowser flashes a chrome redirect immediately returns to app in both emulated and physical android
I'm submitting a:
- [ X] Bug report
- [ ] Feature request
- [ ] Other (Describe below)
Current behavior
I have followed the instructions to configure okta-react-native for a RN android application.
I have a button which has an
await signInWithBrowser();
call on onPress.
When I click the button, chrome opens with seemingly the correct 'discoveryUri' The browser immediately exists and the thrown exception has an error message of: "Error: Error not specified."
Expected behavior
The browser should stay open and provide me the ability to login, returning an object containing the access token.
- Package Version: "@okta/okta-react-native": "^2.2.0",
- React Native Version: "react-native": "0.66.3",
- OS: Android 11
- Node version (
node -v
): v16.12.0 - Other:Android Studio Bumblebee Beta 3, M1 Mac
Relevant files
In okta config
requireHardwareBackedKeyStore: false
MainApplication.java
package com.testname.sensorinstall;
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.zoontek.rnpermissions.RNPermissionsPackage;
import org.reactnative.camera.RNCameraPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}
// Required for rn built in EventEmitter Calls.
@ReactMethod
public void addListener(String eventName) {
}
@ReactMethod
public void removeListeners(Integer count) {
}
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.testname.sensorinstall.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
android/app/build.gradle
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId 'com.testname.sensorinstall'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.env.get('VERSION_CODE').toInteger()
versionName project.env.get('VERSION_STRING')
missingDimensionStrategy 'react-native-camera', 'general'
manifestPlaceholders = [
appAuthRedirectScheme: 'com.testname.sensorinstall'
]
}
...
android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
maven { url 'https://www.jitpack.io' }
maven { url "https://dl.bintray.com/okta/com.okta.android"}
}
}
AndroidManifest.xml
<queries> <intent> <action android:name="android.support.customtabs.action.CustomTabsService" /> </intent> </queries>
</manifest>
Sorry to hear you're running into issues. I don't see anything obviously wrong. Can you give us any more info about the error? A stack trace would be helpful.
My guess is that it's a configuration issue. Have you tried running our sample apps?
For configuration, my call to await createConfig(oktaConfig)
returns true
I will try a sample app Here is the stack trace, I haven't been able to parse this.
WARN Possible Unhandled Promise Rejection (id: 1):
Error: Error not specified.
promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:2568:45
_callee3$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:125225:94
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24265:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24435:32
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24265:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24337:30
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24367:19
tryCallTwo@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:28951:9
doResolve@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:29115:25
Promise@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:28974:14
callInvokeWithMethodAndArg@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24366:33
enqueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24371:157
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24386:69
_callee3@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:125215:38
_callee$@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:124977:131
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24265:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24435:32
tryCatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24265:23
invoke@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24337:30
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24367:19
tryCallTwo@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:28951:9
doResolve@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:29115:25
Promise@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:28974:14
callInvokeWithMethodAndArg@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24366:33
enqueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24371:157
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:24386:69
_callee@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:124970:42
_performTransitionSideEffects@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:63955:22
_receiveSignal@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:63897:45
onResponderRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:63793:34
invokeGuardedCallbackProd@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:3908:21
invokeGuardedCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:4012:42
invokeGuardedCallbackAndCatchFirstError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:4016:36
executeDispatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:4094:48
executeDispatchesInOrder@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:4114:26
executeDispatchesAndRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5374:35
forEach@[native code]
forEachAccumulated@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:4645:22
runEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5398:27
runExtractedPluginEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5478:25
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5453:42
batchedUpdates$1@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:17515:20
batchedUpdates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5360:36
_receiveRootNodeIDEvent@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5452:23
receiveTouches@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:5506:34
__callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:3081:36
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:2805:31
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:3032:15
callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.sensorum.sensorinstall&modulesOnly=false&runModule=true:2804:21
callFunctionReturnFlushedQueue@[native code]
In the sample app, clicking the button doesn't do anything.
That being said I did have some luck with the custom signing earlier, but I couldn't figure out how to hookup MFA for it.
Also, upon further investigation of the createConfig call, it seems to return true even if i input garbage.
@NikitaAvraimov-okta do you have any ideas on this one?
@jackhamburger another option is to reach out to our support team, and they'll be able to help with your configuration. https://support.okta.com/
@jackhamburger AFAIK you won't be able to use MFA with custom sign-in, unfortunately.
MFA Does work with custom sign-in!
@JayNewstrom That's good to hear, I probably just misunderstood this answer then https://github.com/okta/okta-react-native/issues/238#issuecomment-953620118 (I had a problem with MFA and custom sign-in that I was implementing).
MFA should work in all of our SDKs. But it looks like we've missed the mark a little on react-native. We've added a task to our backlog to demonstrate via a sample how to do MFA with react-native.
Internal Ref: OKTA-300537
If you'd like to take a stab at implementing this without a sample, we have a small amount of documentation here: https://github.com/okta/okta-auth-js#node-js-and-react-native-usage