- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Laravel 构建一个 Web 应用程序,该应用程序使用 Google 帐户作为登录方法。我已经从 Github 下载了 Google+ PHP API,并编写了一个单例类来访问 Google+ 服务。此类的片段如下所示:
// Returns a client ready to receive an access token.
private static function getClient() {
if (!self::$client) {
self::$client = new Google_Client();
self::$client->setApplicationName(self::$application_name);
self::$client->setClientId(self::$client_id);
self::$client->setClientSecret(self::$client_secret);
self::$client->setAccessType('offline');
// I'm only requesting the plus.login and userinfo.profile scopes.
self::$client->setScopes(self::$scopes);
// RedirectURI = 'postmessage'
self::$client->setRedirectUri(self::$redirect_uri);
}
return self::$client;
}
// Returns a client ready to be used for API calls.
private static function getClient2() {
$c = self::getClient();
// getToken returns the token session variable. This is the full
// JSON encoded token we got after authenticating the code.
$token = self::getToken();
$c->setAccessToken($token);
if ($c->isAccessTokenExpired()) {
// getRefreshToken returns the refresh_token session variable.
// This is a JSON decoded string that only contains
// the refresh_token value.
$refreshToken = self::getRefreshToken();
// This is the line that blows up.
$c->refreshToken($refreshToken);
// This code has never been reached :(
$newToken = $c->getAccessToken();
self::storeToken($newToken);
}
// If the access_token hasn't expired, we can merrily begin using
// the client to construct a Google_Service_Plus object.
return $c;
}
我正在实现混合客户端/服务器流程。用户首次登录时,将调用 JavaScript 回调,发送要进行身份验证的代码。用户已通过身份验证,refresh_token
存储在数据库和当前 session 中,我可以在 access_token
的生命周期内成功进行 API 调用。
一小时后,访问 token 过期。我在 getClient2()
中对此进行了测试,并尝试使用从 session 中检索到的 refresh_token
刷新 access_token
(我已经打印了 session 变量和可以确认它们存在并且是 json_decoded)。然后我得到了漂亮的描述性错误
Error refreshing the OAuth2 token, message: 'invalid_grant'
此时所有依赖于 Google+ 的页面都显示错误页面。除非用户返回到网站主页,否则 JavaScript 会再次开始登录流程,从而允许服务器在另一个小时内获得有效的 access_token
,否则该网站将变得无响应。
如果需要,我可以发布更多单例类,但考虑到我能够在第一个小时内对用户进行身份验证并发出请求,我认为这就是所有相关内容。
类似但没有帮助的问题:
最佳答案
如果您希望使用刷新 token 刷新访问 token ,您可以这样做
$client->refreshToken( $refresh_token );
$_SESSION['token'] = $client->getAccessToken();
如果您尝试刷新您最近授予的刷新 token 以外的内容,您将获得返回的 invalid_grant。
关于php - Google+ 身份验证 : refreshToken() returns invalid_grant error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25300126/
我根据Alamofire自定义refreshTokens函数guide . 当 refreshTokens 失败并从 API 服务器获得 401 状态时,我想重新路由到登录 View (对于其他错误状
根据 Firebase documentation ,刷新 token 是 仅适用于需要显式刷新 token 的高级场景 . 在什么情况下我应该使用该 token ,使用它有什么好处? private
我正在使用 springboot-security-jwt因为有很好的推荐,而且它正在运行......但是当我测试refreshToken时,在哪里实现?如何使用它? 或许对于一个“高级开发者 Spr
在此documentation它提供了调用 Web API 的 Web 应用程序的完整流程: The web application executes a policy and the user co
我在 Android 上的 Google Play 服务 中使用 GoogleAuthUtil。调用 GoogleAuthUtil.getToken(context, userName, scope)
我想在我的客户端应用程序中实现授权,但我在使用 Keycloak 更新 React 应用程序中的 token 时遇到了问题。 App.js import keycloak from "../../ke
我正在尝试使用服务帐户创建凭据(以便检索 Google Analytics(分析)信息)。 但是当 Credential.refreshToken(..) 被调用时,我得到一个 java.net.So
我有一个 Android 应用程序,它应该使用谷歌融合表。我使用的是谷歌服务帐户,必须获取我的 xxxxxxxxxxxprivatekey.p12 的路径。 public class Credenti
每当我们使用 DotNetOpenAuth 刷新我们的授权时,响应中都会包含一个新的 Oauth2.0 RefreshToken。由于 RefreshToken 本身是一个长期存在的 token ,我
我正在构建一个需要访问我们客户的 Office 365 Management Activities 的应用程序。我已按照this Azure Active Directory中概述的步骤进行操作概述,
我希望我的应用程序中的用户保持登录状态。我正在使用带有 IDToken 的 Firebase 身份验证,它持续 1 小时,直到它过期。如果 session 即将过期,我想每次都自动刷新 session
我正在使用 React-Router V4,我想移交“经过身份验证”的属性来决定是将用户发送到登录页面还是请求的页面: PrivateRoute.js import React from "react
我尝试使用此代码通过 Google.Apis.Auth.OAuth2 库获取应用程序的 Google 刷新 token 。当我在 localhost 上使用它时,它工作完美,但是当我在 Azure 站
我被这种行为难住了。基本上,当请求刷新 token 时,WebAPI 会执行从数据中删除旧 refresh_token 的逻辑,我在调试器中没有看到任何错误。但是,API 返回一个 HTTP 400,
我正在使用 Laravel 构建一个 Web 应用程序,该应用程序使用 Google 帐户作为登录方法。我已经从 Github 下载了 Google+ PHP API,并编写了一个单例类来访问 Goo
我正在尝试将 Google 日历集成到我的应用程序中,但我在传递 RefreshToken 的 OAuth 授权方面遇到了一些问题。我收到一个没有问题的 AccessToken,但 RefreshTo
我正在尝试使用授权码将视频上传到 Youtube。 public Credential authorize(List scopes, String credentialDatastore)
我正在使用 资源所有者密码授予 与 spring-security-oauth 在后端。代币是 智威汤逊 . 我想要短期访问 token (比如 2 分钟)但长期刷新 token (比如每小时)。 据
google API 有很多示例代码展示了如何获取授权 token 并使用它,但我找不到任何展示如何在 java 中使用 Oauth 2.0 GoogleAccessProtectedResource
配置 firebase 的简单应用程序 ... import * as firebase from "firebase/app"; import 'firebase/auth'; const app
我是一名优秀的程序员,十分优秀!