AppAuth-iOS icon indicating copy to clipboard operation
AppAuth-iOS copied to clipboard

Is it possible to get fresh token synchronously?

Open h3dkandi opened this issue 4 years ago • 4 comments

From what I gathered all callbacks in the -[performActionWithFreshTokens] function are performed on the main tread/queue.

Even if I use -[performActionWithFreshTokens:additionalRefreshParameters:dispatchQueue:] that will only execute my callback/action on the specified thread. There is still logic inside the method that dispatches to the main tread/queue. It calls -[OIDAuthorizationService performTokenRequest:originalAuthorizationResponse:callback:] which dispatches its callback on the main thread.

This in turn stops me from hacking the method to become synchronous by blocking the main thread and waiting for my callback. Because if I block it the underlying logic that has dispatches on the main thread won't run. (I know blocking main thread is bad but I will live with it if it does the job)

I understand that for my problem to be solved AppAuth should not execute everything on the main thread. Currently because AppAuth is not thread safe that can not be done. Probably making it thread safe is a huge task.

Is there a way that I can currently do what I want even in a hacky way?

h3dkandi avatar Dec 02 '21 14:12 h3dkandi

I found out that there was an Issue #46 about some callbacks being executed on the main thread when it is not aways wanted. However only one of the suggested methods got the change with #273.

Would something in the project break by dispatching to a custom "com.appauth.OIDAuthorizationService" queue in -[OIDAuthorizationService performTokenRequest:originalAuthorizationResponse:callback:]? Alternatively a queue could be passed as an argument as with performActionWithFreshTokens?

h3dkandi avatar Dec 03 '21 14:12 h3dkandi

Really!

fadedman14 avatar Jan 07 '22 01:01 fadedman14

@petea @julienbodet can you have a look at this issue, please.

We have the same behaviour, we are setting a dispatchQueue which is not used everywhere in AppAuth SDK

imranMnts avatar Jun 27 '22 10:06 imranMnts

Anyone looking at this?

jonathanarevalogaray avatar Sep 07 '22 15:09 jonathanarevalogaray