有可能通过谷歌一键登录获得授权码吗



我试图在有人点击后获得授权码,我正在获得客户端id和证书。但我想获得授权码以便获得访问令牌。基本上我正在获得访问令牌,但我没有获得刷新令牌。所以我如何获得刷新令牌?有人能提出任何解决方案吗?这是我的代码

<html lang="en">
<head>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<script src="https://apis.google.com/js/client.js?onload=authorize"></script>
</head>
<body>
<h2>Infinity</h2>
<div
id="g_id_onload"
data-client_id="xxx"
data-callback="handleCredentialResponse"
></div>
<script>
function handleCredentialResponse(response) {
const config = {
scope: "https://www.googleapis.com/auth/plus.business.manage",
client_id: "xxx",
immediate: true,
response_type: "permission",
};
console.log(response, "here i am getting the credentials and client_id");
gapi.auth2.authorize(config, function (response) {

console.log(response,'here i am getting the access token ');
// i wanted the refresh token 
});
}
</script>
</body>
</html>

若要获得可交换为刷新令牌的代码,必须显示OAuth同意页面并获得最终用户的批准(即使之前已为客户端批准了所有请求的作用域(。根本原因是,刷新令牌表示长期的权限授予。用户必须知道并批准这一点。

总之,不可能以静默方式获取代码(用于新刷新令牌(。是否使用谷歌一键点击并不重要。

如果你已经知道用户的电子邮件,你可以用loginhint:https://accounts.google.com/o/oauth2/v2/auth?login_hint=user_email &scope=scopes&response_type=code&state=respond_with_code&redirect_uri=redirect_uri&client_id=client_id调用OAuth URL,它不会打开同意屏幕,调用此URL的唯一缺点是,它会将用户重定向到redirect_uri,但您将获得授权代码。

最新更新