OAuth的V2(谷歌API)到期日访问令牌 [英] OAuth v2 (Google API) expiry Access Token

查看:415
本文介绍了OAuth的V2(谷歌API)到期日访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用图形框架谁拥有pre-构建的OAuth2连接器的集成组件。
该框架需要进行以下的OAuth的v2的领域:

I am building an integration component using a graphical framework who has a pre-build OAuth2 connector. This framework required following fields for OAuth v2:


  • 捐赠类型

  • 范围

  • Auth服务器网址

  • 客户端编号

  • 客户端揭秘

  • 访问令牌

  • 刷新标记

我需要从谷歌Analytics(分析)API的数据,所以我去了谷歌开发控制台
https://console.developers.google.com/project/927890000889/apiui/凭据)。我产生了'的Web应用程序客户端ID。从这个对象的参数,我能够填补一些参数上面

I need to get data from Google Analytics API, so I went to Google Dev Console (https://console.developers.google.com/project/927890000889/apiui/credential). I generated a 'Client ID for web application'. From the parameter of this object I was able to fill some of the parameters above


  • 捐赠类型:'authorisation_ code

  • 客户端编号:'RANDOMCHARSam5o37nsiu730d.apps.googleusercontent.com

  • 客户端秘密:RANDOMCHARSiSwBA5OH5qYLUa

https://developers.google.com/oauthplayground )我是能够填补缺失的位

Then using Google Oauth Playground (https://developers.google.com/oauthplayground) I was able to fill the missing bits

一切正常,我授权的访问,我从谷歌Analytics(分析)中获取数据,但只是一会儿,几分钟后如果我重试后,我收到授权失败错误。
我认为,这个问题涉及到访问令牌到期,但我不知道该怎么解决。
值得一提的是本次活动是批次(无人机交互),所以没有人可以请求新的访问令牌。
集成框架是不可扩展的(我不能写code续签code),所以我相信有一种方式来获得一个访问令牌永不过期或一些其他机制来实现相同的结果。

Everything works fine, I am authorised to access and I get data from Google Analytics, but just for a while, after few minutes if I retry I receive an authorisation failure error. I believe that the problem is related to the expiration of the Access Token, but I don't know how to solve that. Worth to mention that this activity it's batch (no human interaction), so nobody can request a new access token. The integration framework is not extensible (I cannot write code to renew the code) so I believe there's a way to get a access token that never expire or some other mechanism to achieve the same result.

底线,我不知道我是否正确地走近年初以来(对于Web应用程序客户端ID)的要求。

Bottom line, I am not sure if I approached the requirement correctly since the beginning (Client ID for web application).

任何帮助很多AP preciated,
乔瓦尼

Any help is much appreciated, Giovanni

推荐答案

访问令牌通常为60分钟后过期。如果你有一个刷新令牌可以使用刷新令牌来获取新的(有效)访问令牌。

Access tokens typically expire after 60 minutes. If you have a refresh token you can use the refresh token to get a new (valid) access token.

本文档介绍了如何做到这一点:结果
https://developers.google.com/accounts/docs/OAuth2WebServer#refresh

This doc explains how to do that:
https://developers.google.com/accounts/docs/OAuth2WebServer#refresh

要回答你的问题,首要的,是的,你是正确的接近一切。所有你需要做的是处理的情况下访问令牌已经通过刷新它过期的情况。此外,当您最初请求访问令牌的响应应该告诉你它有多长的有效期,因此,如果它过期,你应该只刷新该令牌。

To answer your overarching question, yes, you are approaching everything correctly. All you need to do is handle the case where the access token has expired by refreshing it. Also, when you originally requested the access token the response should tell you how long it's valid for, so you should only refresh that token if it's expired.

这篇关于OAuth的V2(谷歌API)到期日访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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