Android 上的 Signpost OAuth:如何在两次连续运行之间重新创建 Consumer?
我成功地使用 Signpost 通过 OAuth 授权调用 Google 帐户中的受保护资源。
然而,用户每次都必须通过 Google 并授予访问权限,这似乎有点奇怪。有没有一种方法可以序列化 Consumer 并重新创建它,以便不需要重新授权?我尝试将令牌、秘密和验证程序保留在共享首选项中,并将它们设置在消费者中,但我收到了 OAuthExpectationFailedException。
有什么想法吗?
I'm succesfully using Signpost to authorize calls to protected resources in a Google account via OAuth.
However it seems a bit weird that the user has to go each and every time through Google and grant access. Is there a way of serializing the Consumer and recreating it so that re-authorization is not needed? I've tried keeping the tokens, secret and verifier in the shared preferences and setting them in the Consumer but I receive a OAuthExpectationFailedException.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
收到访问令牌后,您可以将其存储在您的应用程序首选项中,如下所示:
之后,您可以随时重新创建消费者,如下所示:
一旦获得消费者,您就可以进行 API 调用,消费者将签署他们。
根据signpost 文档:
Signpost 对象非常轻量级,因此建议您为应用程序中必须发送签名 HTTP 请求的每个线程创建 OAuthConsumer 和 OAuthProvider。这两个对象也是可序列化的,因此您可以保留它们并在以后恢复它们。
Once you've received the access token, you can store it in your apps preferences like this :
Afterwards, you can always re-create the consumer like this :
Once you've got the consumer, you can make API calls and the consumer will sign them.
According to the signpost docs :
Signpost objects are very lightweight, so you are adviced to create an OAuthConsumer and OAuthProvider for every thread in your application that must send signed HTTP requests. Both objects are also serializable, so you can persist and restore them later.