telenordigital / connect-android-sdk

Android SDK for CONNECT ID
https://telenordigital.github.io/id-docs.telenordigital.com/
Other
16 stars 14 forks source link

NullPointerException when refresh token #32

Closed infinityzero closed 8 years ago

infinityzero commented 8 years ago

When I call below method:

ConnectSdk.updateTokens(new ConnectCallback() {
    @Override
    public void onSuccess(Object successData) {
        // ...
    }
    @Override
     public void onError(Object errorData) {
         // ...
     }
});

Got below exception:

Fatal Exception: java.lang.NullPointerException
       at com.telenor.connect.id.ConnectIdService.getRefreshToken(ConnectIdService.java:76)
       at com.telenor.connect.id.ConnectIdService.updateTokens(ConnectIdService.java:120)
       at com.telenor.connect.ConnectSdk.updateTokens(ConnectSdk.java:255)
       at android.os.AsyncTask.finish(AsyncTask.java:632)
       at android.os.AsyncTask.access$600(AsyncTask.java:177)
       at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5111)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
       at dalvik.system.NativeStart.main(NativeStart.java)
jorunfa commented 8 years ago

Hi. You are getting this exception because retrieveTokens returns null and then null.getRefreshToken() is called. There are no tokens. Is a user signed in?

image

This issue seems similar to https://github.com/telenordigital/connect-ios-sdk/issues/19. Are you also using some sort of middle-ware server?

infinityzero commented 8 years ago

Yes, I'm using middle-ware server to verify connect access token.

infinityzero commented 8 years ago

Yes, user already signed in.

jorunfa commented 8 years ago

How do you currently keep track of when the accessToken expires, and when to update the tokens?

I see now that the SDK does not have the functionality to keep track of this. I could also make it so that the SDK did this for you. Is this functionality wanted?

infinityzero commented 8 years ago

I'm not keep track of access token in Android. Update the token when received session expire from our middle-ware server.

Please see the below flow:

  1. Get the access token by calling ConnectSdk.getAccessToken().
  2. Send it to our middle-ware server
  3. Middle-ware server check it (from Connect server) and response to Android
  4. If session expire response, call ConnectSdk.updateTokens(...)

If SDK have the functionality to keep track of access token, that would be great.

jorunfa commented 8 years ago

Great. Working on it #33. You will be able to call getValidAccessToken(…).

After the pull request is merged I will have to later release a new version of the SDK, after some testing, then you can use it.

jorunfa commented 8 years ago

33 is now merged into the development branch. Hopefully within the next couple of days we can run validation testing and make a new release if everything works as expected.

jorunfa commented 8 years ago

The newest release now has this feature: https://github.com/telenordigital/connect-android-sdk/releases