Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied

I have implemented google drive functionality for file management its working fine in local system but whenever i hosted it on Godaddy server it throw following error

System.UnauthorizedAccessException Access to the path 'Google.Apis.Auth' is denied.

Following code i am using :

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   new ClientSecrets
   {
       ClientId = System.Configuration.ConfigurationManager.AppSettings["GDriveClientId"],//Get ClientID from web.config.
       ClientSecret = System.Configuration.ConfigurationManager.AppSettings["GDriveClientSecret"]//Get ClientSecret from web.config.
   },
   new[] { DriveService.Scope.Drive },
   System.Configuration.ConfigurationManager.AppSettings["GDriveCreatedByUser"],//Get UserName from web.config.
   CancellationToken.None).Result;

return credential;

I am using VS2010,IIS 7 for above functionality

like image 328
Chandrika Prajapati Avatar asked May 01 '14 10:05

Chandrika Prajapati


People also ask

How do I fix system UnauthorizedAccessException access to the path?

Resolving "Access Path is Denied" error To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties", and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account and check the boxes for the desired access.

What is System UnauthorizedAccessException?

An UnauthorizedAccessException exception is thrown when the operating system denies access because of an I/O error or a security error. If you are attempting to access a file or registry key, make sure it is not read-only.


2 Answers

Expanding what Chandrika has already said, the ASP.NET user needs read and write permissions to the Google API Client OAuth2 Library's permanent storage folder .

Its default value is a folder named "Google.Apis.Auth" in Environment.SpecialFolder.ApplicationData (which usually corresponds to C:\Users\your-user-name\AppData\Roaming).

Alternatively, another folder can be provided as the last parameter of the GoogleWebAuthorizationBroker.AuthorizeAsync() method:

var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
   new ClientSecrets
   {
       ClientId = "PutYourClientIdHere",
       ClientSecret = "PutYourClientSecretHere"
   },
   new[] { DriveService.Scope.Drive },
   "user",
   CancellationToken.None,
   new FileDataStore(folder)).Result;

return credential;

See: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#credentials and https://developers.google.com/accounts/docs/OAuth2

like image 187
f.cipriani Avatar answered Sep 21 '22 06:09

f.cipriani


Root cause of the problem : This issue is generated because after validating authentication request its create directory and token file under in window's user's folder and we have not right's for that folder of Godadday server so it was not working

Solution : Modified the source code of google apis[filedatasource.cs] for creating that file inside our directory and add reference of it and it will work

like image 27
Chandrika Prajapati Avatar answered Sep 21 '22 06:09

Chandrika Prajapati