Appauth-android: Run AuthService outside of activity context

Created on 25 Apr 2018  路  5Comments  路  Source: openid/AppAuth-Android

I suddently ran into a weird issue when running AppAuth in my android app in an emulator. Everything works fine on phone, as far as I am concerned but the following exception is thrown inside emulator:

04-25 11:29:52.582 5103-5103/com.myfuturity.futurity W/System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

I tracked the issue down and we are not injecting activity context into the auth state manager and it is apparently needed. We are using KOIN for dependency injection (including context) and all our AppAuth services are injected via Koin.

Is there some workaround that would enable us running AppAuth with application context (that's the one being injected)? Setting the FLAG_NEW_TASK to the auth intent does not work, unfortunately.

Thank you for the clarification.

enhancement

Most helpful comment

Any news?

All 5 comments

We had this same issue and resolved it by using an activity context for a one off instance of AuthorizationService just in our login activity and cleaning it up in onStop. We inject the one based on application context everywhere else.

I should probably expose a variant of getAuthorizationRequestIntent that allows you to specify the completion and cancelation PendingIntents, so that you can call startActivity yourself with the correct context. Alternatively, I could allow the context to be overridden with a parameter passed to performAuthorizationRequest.

Hi,
What is the recommended way of doing this? I am stuck on this error and can't seem to find a way to get around this.

Any news?

Someone already figured out a workaround? We also encapsulated the entire authorization process into a separate module, while using KOIN to inject the androidContext.

Was this page helpful?
0 / 5 - 0 ratings