我在我的单页 (javascript) 应用程序中使用 google HTML 登录按钮从使用 Google 登录的用户那里获取授权对象。这在此处进行了详细说明:https ://developers.google.com/+/web/signin/add-button 。
我成功收到了一个令牌,如下所示。由于此令牌在 1 小时后到期,因此我需要每 30 分钟左右刷新一次令牌,直到用户选择注销。我正在尝试通过调用:
gapi.auth.authorize({client_id: "90... ...92.apps.googleusercontent.com", scope: "profile email", immediate: true}, function() { console.log( arguments ); } );
但没有运气。我收到相同的令牌,直到它过期,之后我取回空(未登录)令牌。如何在用户不必不断再次登录的情况下保留/刷新不记名令牌?
{
_aa: "1"
access_token: "ya29.1.AA... ...BByHpg"
authuser: "0"
client_id: "90... ...92.apps.googleusercontent.com"
code: "4/Nyj-4sVVcekiDnIgMFh14U7-QdRm.svPMQSODiXMbYKs_1NgQtmX9F90miwI"
cookie_policy: "single_host_origin",
expires_at: "1398341363",
expires_in: "3600",
g_user_cookie_policy: undefined,
id_token: "eyJhbGciOiJ... ...0Es1LI"
issued_at: "1398337763",
num_sessions: "2",
prompt: "none",
response_type: "code token id_token gsession",
scope: "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
session_state: "b92d67080... ...73ae",
state: "",
status: {
google_logged_in: true,
method: "AUTO",
signed_in: true
},
token_type: "Bearer"
}