gpt4 book ai didi

c# - 如何在 asp.net 中生成刷新 token ?

转载 作者:太空宇宙 更新时间:2023-11-03 14:41:58 25 4
gpt4 key购买 nike

我可以使用谷歌文件选择器从客户端获取访问 token 。但是访问 token 在 3600 秒后过期。我绞尽脑汁想获取刷新 token ,但无法在 C# ASP.NET 上执行此操作。有人可以帮助 C# 代码理解和检索刷新 token 吗?这将非常有帮助。谢谢。

我尝试使用 GoogleWebAuthorizationBroker.AuthorizeAsync,它可以在我的本地计算机上运行,​​但不能在生产 IIS 服务器上运行。我还尝试了 GoogleAuthorizationCodeFlow,但无法继续使用,而且我不知道如何使用它。

IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = System.Configuration.ConfigurationManager.AppSettings["GoogleDriveClientID"],
ClientSecret = System.Configuration.ConfigurationManager.AppSettings["GoogleDriveClientSecret"]
},
Scopes = Scopes,
DataStore = null
});

我试过了,但我不知道在这之后如何前进。

最佳答案

您似乎正在尝试从您的 C# 代码示例生成刷新 token 。

您可以尝试以下代码片段:

刷新 token 示例:

public class AppFlowMetadata : FlowMetadata
{
private static readonly IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "yourClientId",
ClientSecret = "yourClientSecret"
},
Scopes = new[] { DriveService.Scope.Drive },
DataStore = new FileDataStore("Drive.Api.Auth.Store")
});

public override string GetUserId(Controller controller)
{
// In this sample we use the session to store the user identifiers.
// That's not the best practice, because you should have a logic to identify
// a user. You might want to use "OpenID Connect".
// You can read more about the protocol in the following link:
// https://developers.google.com/accounts/docs/OAuth2Login.
var user = controller.Session["user"];
if (user == null)
{
user = Guid.NewGuid();
controller.Session["user"] = user;
}
return user.ToString();

}

public override IAuthorizationCodeFlow Flow
{
get { return flow; }
}
}

注意:如果您对如何获得 ClientId 有任何疑问, ClientSecretScope ,请引用这个MVC Example .

关于c# - 如何在 asp.net 中生成刷新 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56371951/

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