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
相关产品推荐
相关产品推荐

