我成功地使用 GoogleAuthorizationCodeFlow 来获取和存储凭据以访问 Google Calendar API。我想使用include_granted_scopes=true
查询参数进行增量授权。
我搜索了很长时间,但无法弄清楚如何包含include_granted_scopes
参数。有没有办法这样做?
我成功地使用 GoogleAuthorizationCodeFlow 来获取和存储凭据以访问 Google Calendar API。我想使用include_granted_scopes=true
查询参数进行增量授权。
我搜索了很长时间,但无法弄清楚如何包含include_granted_scopes
参数。有没有办法这样做?
首先获取您的授权网址
GoogleAuthorizationCodeRequestUrl authUrl = googleAuthorizationCodeFlow.newAuthorizationUrl();
授权 url 只是 a 的一个实例GenericUrl
,因此您可以使用GenericUrl.set(key, value)设置任意查询参数。
authUrl.set("include_granted_scopes", true);
尝试以下操作:
var googleOAuthOptions =
new GoogleOAuth2AuthenticationOptions()
{
ClientId = "...",
ClientSecret = "...",
Provider = new GoogleOAuth2AuthenticationProvider
{
OnApplyRedirect = context =>
{
var redirect = context.RedirectUri;
redirect += "&include_granted_scopes=true";
context.Response.Redirect(redirect);
}
}
};
googleOAuthOptions.Scope.Add(...);
app.UseGoogleAuthentication(googleOAuthOptions);