好的,所以我正试着在我的.Net网络应用程序(Blazor)中设置OAuth到Google.
我已经设置了请求授权码的第一部分并正在进行工作.
然而,一旦我有了验证码,我就应该把它换成令牌并刷新令牌.
为此,我使用了Google.Net Auth库.我找到了一个样品并试了试,但我得到的唯一结果是:Error:"invalid_grant", Description:"Bad Request", Uri:""
我在这上面搜索了一下,找到了this个.我已经判断了所有可能的问题,但没有一个适用于我的测试.即,时钟未关闭、用户(我)未撤销访问权限、密码最近未更改等.
在我看来,这个调用应该不难,但我花了几个小时try 调试它.我正在使用官方的库来解决这个问题,但我怀疑有些东西不能正常工作.代码是这样的:
GoogleAuthorizationCodeFlow authorizationCodeFlow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
DataStore = dataStore,
ClientSecrets = new ClientSecrets()
{
ClientId = clientId,
ClientSecret = clientSecret
}
});
try
{
var tokenResponse = await authorizationCodeFlow.ExchangeCodeForTokenAsync(
userId, // user for tracking the userId on our backend system
authorizationCode,
"https://localhost:7155/gauth", // redirect_uri can not be empty. Must be one of the redirects url listed in your project in the api console
CancellationToken.None);
我该怎么办?跳过.Net库,直接从我自己的代码调用API?
每次获取授权码的第一次调用都能完美地工作,不确定为什么这一步如此困难.