user3401566
user3401566

Reputation: 1

Access to the path Google.Apis.Auth is denied

I was trying to implement google calender event sync functionality to schedule event from my local application to google calendar. its working fine in local system but whenever I deployed it on server, it throws the following error.

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

Below is the code which I am using for same.

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        new ClientSecrets
        {
            ClientId = "xxx-9khdjsqifkj2amsji2jce37p8lfn0166.apps.googleusercontent.com",
            ClientSecret = "ZdsrCa-uwG3GmpVLTfYDli-S",
        },
        new[] { CalendarService.Scope.Calendar },
        "user",
        CancellationToken.None).Result;

        // Create the service.
        var service = new CalendarService(new BaseClientService.Initializer
        {
            HttpClientInitializer = credential,
            ApplicationName = Summary,
        });

Upvotes: 0

Views: 3207

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116868

By default the Google .Net client library uses FileDatastore() file datastore by default stores the credentials in %appData%. When you run your application under what ever user it is you are running you don't apperntly have access to %appData%

string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);

var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        new ClientSecrets
        {
            ClientId = "xxx4671204-9khdjsqifkj2amsji2jce37p8lfn0166.apps.googleusercontent.com",
            ClientSecret = "ZdsrCa-uwG3GmpVLTfYDli-S",
        },
        new[] { CalendarService.Scope.Calendar },
        "user",
        CancellationToken.None,
        new FileDataStore(credPath, true)).Result;

Make sure that credPath is some place that you have access to write to. I have a sample on GitHub for Google calendar Oauth2 and I have a tutorial on how filedatastore works FileDatastore demystified

Upvotes: 4

Related Questions