okta / okta-oidc-android

OIDC SDK for Android
https://github.com/okta/okta-oidc-android
Other
60 stars 45 forks source link

Feature Request: Coroutines Support #286

Closed pjkarels closed 2 years ago

pjkarels commented 2 years ago

I get the exception NetworkOnMainThreadException when attempting to call AuthenticationClient.authenticate() when using Kotlin Coroutines. Are there plans to support coroutines?

JayNewstrom commented 2 years ago

You may be mistaking SDKs.

https://github.com/okta/okta-auth-java/blob/master/api/src/main/java/com/okta/authn/sdk/client/AuthenticationClient.java

AuthenticationClient is part of okta-auth-java.

That being said, the calls are meant to happen on a background thread. Are you sure you're switching threads? Could you try something like this?

val scope = CoroutineScope(Dispatchers.IO)
scope.launch {
        authenticationClient.authenticate(...)
}
pjkarels commented 2 years ago

@JayNewstrom, thank you - I was leaving out the Dispatcher.IO arg. Adding it makes it work nicely.