Permission denied to save oAuth2 token on plesk server

78 Views Asked by At

I'm using oAuth2 Google validation for file uploads in Google drive with asp.net/mvc project. It is well working in Visual Studio 2022 but when I deploy to the server and I visit the authentication page, the error http 403 forbidden access denied is shown.

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();
   }

I want to upload files in Google drive without using service account because it has a 15gb storage limit. This is automated project to upload files in Google drive so I want to visit only once for email verification.

screenshot

0

There are 0 best solutions below