Access to the path 'C:\Windows\system32\config\systemprofile' is denied when using Google.Api OAuth 2

10,511

Solution 1

As per https://domantasjovaisas.wordpress.com/2014/09/27/demystifying-google-api-and-oauth2/ :

From code I just provided you can see that I’m using File2DataStore. It’s overridden by me. Standard FileDataStore I changed to my own needs. Standard FileDataStore stores auth keys in “C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\Drive.Api.Auth.Store”

I don’t think so that you will allow IIS_IUSRS users access this location in production environment 🙂 Think twice, don’t do that. Rewrite FileDataSource to your own needs. Here is two examples how you can do it :

https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis.DotNet4/Apis/Util/Store/FileDataStore.cs http://www.daimto.com/google-oauth2-csharp/#FileDataStore

In short, you need to stop using FileDataStore and write your own replacement (using the above links as your starting points).

Solution 2

The problem is that by default

 new FileDataStore("Calendar.Api.Auth.Store") 

stores data at path that requires special permission so instead send full path as parameter.

Instead of

    new FileDataStore("Calendar.Api.Auth.Store") 

send full path to where you want to save in your file system and second parameter set to true for example

    new FileDataStore(fullpath, true);

That should work. Good luck

Solution 3

I don't think you give permission to this folder C:\Windows\system32\config\systemprofile. Try using absolute path like this image or convert a relative path to absolute (by using server map path).

Make sure you have enough permission on this folder.

enter image description here

Share:
10,511
Divya
Author by

Divya

I'm a software engineer and currently i've 3.5 years of experience.

Updated on June 09, 2022

Comments

  • Divya
    Divya almost 2 years

    I am using Google Calendar Api with one of my project. I don't know how but Error Shown Below is troubling.

    Here is the Error

    Stack Trace of Error

    Code inside AppFlowMetadata.

    public class AppFlowMetadata : FlowMetadata
    {
        private static readonly IAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = new ClientSecrets
                {
                    ClientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
                    ClientSecret = "xxxxx_xxxxxxxxxxxxxxxxx"
                },
                Scopes = new[] { CalendarService.Scope.Calendar },
                DataStore = new FileDataStore("Calendar.Api.Auth.Store")
            });
    
        public override string GetUserId(Controller controller)
        {
            var user = controller.Session["UserID"];
    
            if (user == null)
            {
                user = Guid.NewGuid();
                controller.Session["UserID"] = user;
            }
            return user.ToString();
    
        }
    
        public override IAuthorizationCodeFlow Flow
        {
            get { return flow; }
        }
    }
    

    I tried below solution from GitHub but isn't working

    I tried this Solution

    Above solution didn't worked for me, if any have the answer please help.