Google OAuth 403刷新访问令牌时 [英] Google OAuth 403 when refreshing access token
问题描述
string tokenRequestBody = string.Format(code = {0}& redirect_uri = {1}& client_id = {2}& scope& grant_type = authorization_code,
code,
System.Uri.EscapeDataString (redirectURI),
clientID
);
StringContent content = new StringContent(tokenRequestBody,Encoding.UTF8,application / x-www-form-urlencoded);
HttpResponseMessage response = new HttpClient()。PostAsync(https://www.googleapis.com/oauth2/v4/token,content).Result;
在响应中的这一点,我有一个刷新令牌和一个全功能的1小时访问令牌。这是行得通的。
现在我想使用刷新令牌来更新访问令牌:
string tokenRequestBody = string.Format(client_id = {0}& refresh_token = {1}& grant_type = refresh_token,clientID,_refreshToken);
StringContent body = new StringContent(tokenRequestBody,Encoding.UTF8,application / x-www-form-urlencoded);
HttpResponseMessage tokenResponse = new HttpClient()。PostAsync(https://www.googleapis.com/oauth2/v4/token,body).Result;
而不是获取新的访问令牌,我有以下错误:
[{domain:usageLimits,reason:dailyLimitExceededUnreg,message:未经验证的使用的每日限制超出。注册。,extendedHelp:https://code.google.com/apis/console}],code:403,message:未经验证的使用的每日限制超出,继续使用需要注册。 }
我在这里错过了什么?
感谢您的帮助。
好的,我真的很蠢。
上面的代码没有任何问题。
基本上我是这样做的:
var dataResponse = getSomeStuffFromRestApi();
if(api授权失败)
{
var tokenResponse = getATokenFromRestApi();
lookForTokenInResponse(dataResponse); //应该是tokenResponse .............
}
对不起,浪费时间。至少有一些工作代码供参考....
In a UWP app, I first get a refresh token and an access token using the following endpoint :
string tokenRequestBody = string.Format("code={0}&redirect_uri={1}&client_id={2}&scope=&grant_type=authorization_code",
code,
System.Uri.EscapeDataString(redirectURI),
clientID
);
StringContent content = new StringContent(tokenRequestBody, Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage response = new HttpClient().PostAsync("https://www.googleapis.com/oauth2/v4/token", content).Result;
At this point in the response, i have a refresh token and a fully functional 1 hour access token. This is working fine.
Now i want to use the refresh token to renew the access token :
string tokenRequestBody = string.Format("client_id={0}&refresh_token={1}&grant_type=refresh_token", clientID, _refreshToken);
StringContent body = new StringContent(tokenRequestBody, Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage tokenResponse = new HttpClient().PostAsync("https://www.googleapis.com/oauth2/v4/token", body).Result;
Instead of getting a new access token, i have the following error :
[{"domain":"usageLimits","reason":"dailyLimitExceededUnreg","message":"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.","extendedHelp":"https://code.google.com/apis/console"}],"code":403,"message":"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."}
What am i missing here ?
Thanks for the help.
Well, i'm amazingly stupid.
Nothing at all is wrong with the above code. I just parsed the wrong response.
Basically i did :
var dataResponse = getSomeStuffFromRestApi();
if (api authorization fails)
{
var tokenResponse = getATokenFromRestApi();
lookForTokenInResponse(dataResponse); // should've been tokenResponse.............
}
Sorry for the waste of time. At least there is some working code for reference now....
这篇关于Google OAuth 403刷新访问令牌时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!