You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET/MVC部署Plesk服务器后Google OAuth2授权403错误求助

ASP.NET/MVC Google OAuth2验证部署Plesk后403错误及Token保存权限问题
  • 本地Visual Studio 2022环境中,基于Google OAuth2验证实现的Google Drive文件上传功能运行正常
  • 部署到Plesk服务器后,访问授权页面时出现http 403 forbidden access denied错误,同时提示Permission denied to save oAuth2 token
  • 因服务账号存在15GB存储限制,不考虑使用服务账号;项目为自动化上传需求,希望仅完成一次邮箱验证即可实现后续自动上传

相关代码如下:

public ActionResult GetDriveService() //default route to direct go to validation page of Google
{
        var secrets = new ClientSecrets
        {
            ClientId = ClientId,
            ClientSecret = ClientSecret
        };

        IDataStore dataStore = new FileDataStore(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Drive.Auth.Store"));

        IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
        {
            ClientSecrets = secrets,
            DataStore = dataStore,
            Scopes = new[] { DriveService.Scope.DriveFile },
        });

        string url = flow.CreateAuthorizationCodeRequest(RedirectUri).Build().ToString();

        return Redirect(url);
}

//oauth2 callback method (define at cloud console as redirect uri)
public async Task<ActionResult> LogIn(string code)
{
        var clientSecrets = new ClientSecrets
        {
            ClientId = ClientId,
            ClientSecret = ClientSecret
        };

        var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
        {
            ClientSecrets = clientSecrets,
            Scopes = Scopes
        });

        var token = await flow.ExchangeCodeForTokenAsync("user", code, "http://subdomainName.mydomain.net/LogIn/LogIn", CancellationToken.None);

        // Save the string value in the cache
        MemoryCache.Default.Add("googleDriveToken", token, new CacheItemPolicy());

        return View();
}

内容的提问来源于stack exchange,提问作者Anand Sahani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 20:21:07