nxtbgthng / OAuth2Client

Client library for OAuth2 (currently built against draft 10 of the OAuth2 spec)
855 stars 217 forks source link

Error -34018 when refreshing token in iOS 8 #140

Open silentjohnny opened 9 years ago

silentjohnny commented 9 years ago

In iOS 8, refreshing an access token with a refresh token fails with a MissingEntitlement error -34018.

It looks as if the problem is solved by enabling Keychain Sharing, which adds an entitlement to your project.

Anyone else seeing this behaviour? Does the solution work for you too or could you fix it in another way, as this doesn't feel like an ideal setup.

toto commented 9 years ago

Can you check with the latest release?

silentjohnny commented 9 years ago

We ran with last week's release, I don't see any relevant changes this week. But I'll update anyway.

The problem isn't happening in iOS8 anymore, but now it's happening sometimes in iOS 7. What happens is that sometimes accessing the keychain fails, in which case the refresh token isn't replaced in the keychain. The next time an access token expires, the client tries to refresh with an old refresh token, which of course fails.

What could be the problem is that a refresh happens on a background job, e.g., when the app crashed in the background and then later is launched because of an incoming remote notification, geofence transition or ibeacon monitor. In our case, we fetch user data at launch, which uses oAuth. By default, the SecItems are stored kSecAttrAccessibleWhenUnlocked, which means in background, we can not access the keychain.

We are adding other acessible attribute values to see if this solves the problem with erroneuos tokesn too.