We are working on a project which uses Microsoft Graph SDK to implement Excel/OneDrive related functionalities. We have a use-case where we need to serialize and deserialize the IGraphServiceClient
client reference/object.
We tried to deserialize the object but we're getting a NotSerializableException
exception. We were exploring SDK and find ISerializer.java
class but unable to use it in serialization/Deserialization.
Could you please help us how can we get over this issue?
UsernamePasswordProvider authProvider =
new UsernamePasswordProvider(clientId, scopes, userName, password, null, tenantid, clientSecret);
IGraphServiceClient client= GraphServiceClient
.builder()
.authenticationProvider((IAuthenticationProvider) authProvider).buildClient());
It isn't possible and, frankly, there is no value in serializing/deserializing the client itself.
What you really want is to request the
offline_access
scope so that you'll receive arefresh_token
at the same time as theaccess_token
your using to call Microsoft Graph. You can then store therefresh_token
string and use it to receive an updated/freshaccess_token
. You can then create a newIGraphServiceClient
instance using that token whenever you need to make a call to Microsoft Graph.You can get the IAuthenticationProvider as below.
By the way, if you used Maven to install
microsoft-graph-auth
, there will be some issues. Currently there is a mismatch between the source code and maven repository. The source code ofmicrosoft-graph-auth
is fine. So you can download the source code of msgraph-sdk-java-auth and exported it as jar file. Use this jar file instead of using com.microsoft.graph.0.1.0-SNAPSHOT. This will work.Another way is to use Gradle to install
microsoft-graph-auth
. This works fine.