gpt4 book ai didi

c# - Gmail API : forcing the authorization to reprompt the user

转载 作者:行者123 更新时间:2023-11-30 17:43:37 24 4
gpt4 key购买 nike

授权访问 gmailAPI 的凭据似乎以某种方式缓存。当我更改客户端 ID 和密码以及电子邮件地址时,没有任何变化。此外,当我更改范围时,没有任何变化。我正在尝试强制刷新凭据。有没有办法强制凭据重新提示用户?

是否有我可以找到并删除的文件?

我正在使用 c# 和来自 nuget 的 gmail api 包。认证代码是:

 _emailAddress = Settings.EmailAddress;
string clientSecret = Settings.ClientSecret;
string clientId = Settings.ClientId;
ClientSecrets clientSecrets = new ClientSecrets {ClientId = clientId, ClientSecret = clientSecret};
UserCredential credential;
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
clientSecrets,
Scopes,
"user",
CancellationToken.None).Result;

_service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Draft Sender", //applicationName,
});

此外,一旦我获得凭证,我的范围就设置好了:在我删除并更新 secret 和客户端 ID 之前,无法更改范围。此外,它需要两次运行才能生成凭据,第一次导致错误,但第二次导致授权提示。

我很确定发生这种情况是因为凭据以某种方式缓存在某个地方,即使我没有指定任何存储...但我不确定。无论哪种方式,问题似乎都取决于 gmail api 包中的代码,但我无法为我正在处理的问题找到解决方案。

最终,我需要将一个功能部署到一个 ASP 网站,该网站将访问 gmail 帐户作为电子邮件的存储库,因此我需要弄清楚这个授权问题,以便服务器在部署时可以访问电子邮件帐户(或之后很容易)。在没有中间错误的情况下发生这种情况并不是真的必要(但需要)。

是否有解决方案(简单或困难)来控制此缓存过程并处理权限?

最佳答案

如果您没有指定存储响应 token 的位置,它将存储在:

C:\Users\'你的用户'\AppData\Roaming\Google.Apis.Auth

如果你想指定目录看这个:(注意:你只需要在你的项目中创建目录App_Data)

string path = HostingEnvironment.MapPath("~/App_Data");    
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "Client_ID",
ClientSecret = "Secret_Client"
},
Scopes,
"me",
CancellationToken.None,
new FileDataStore(path)

).Result;

关于c# - Gmail API : forcing the authorization to reprompt the user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30647864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com