如何序列化和反序列化 IGraphServiceClient 客户端对象? [英] How to serialize and Deserialize IGraphServiceClient client object?

查看:117
本文介绍了如何序列化和反序列化 IGraphServiceClient 客户端对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开展一个项目,该项目使用 Microsoft Graph SDK 来实现 Excel/OneDrive 相关功能.我们有一个用例需要序列化和反序列化 IGraphServiceClient 客户端引用/对象.

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.

我们试图反序列化对象,但我们收到了 NotSerializableException 异常.我们正在探索 SDK 并找到 ISerializer.java 类,但无法在序列化/反序列化中使用它.

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.

真正想要的是请求 offline_access 范围,以便您在收到 refresh_token 的同时收到 >access_token 用于调用 Microsoft Graph.然后您可以存储 refresh_token 字符串并使用它来接收更新/新鲜的 access_token.然后,您可以在需要调用 Microsoft Graph 时使用该令牌创建新的 IGraphServiceClient 实例.

What you really want is to request the offline_access scope so that you'll receive a refresh_token at the same time as the access_token your using to call Microsoft Graph. You can then store the refresh_token string and use it to receive an updated/fresh access_token. You can then create a new IGraphServiceClient instance using that token whenever you need to make a call to Microsoft Graph.

这篇关于如何序列化和反序列化 IGraphServiceClient 客户端对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆