Google.Apis.Oauth2.v2 + UWP: Access to path c:\users is denied
Asked Answered
M

1

0

After updating Google.Apis.Oauth2.v2 NuGet package to v. 1.60.0.1869, I start getting exception Access to the path C:\Users is denied when trying login with Google in my UWP app. Here's my code:

string fname = @"Assets\User\Auth\google_client_secrets.json";
StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var stream = await InstallationFolder.OpenStreamForReadAsync(fname);
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    stream,
    new[] { "profile", "email" },
    "me",
    CancellationToken.None);

The exception occurs in GoogleWebAuthorizationBroker.AuthorizeAsync call.

This code (with some light changes) worked well before with Google.Apis.Oauth2.v2 package v. 1.25.0.859, but now this package is obsolete and doesn't work anymore.

How to login with Google in my UWP app?

NOTE: I understand that UWP app doesn't have access to c:\Users, but my code never request anything in the folder. google_client_secrets.json exists and I can read it in the app from the stream, so this file is unrelated to the issue.

UPDATE

After I set the 5th parameter of AuthorizeAsync like this:

credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    stream,
    new[] { "profile", "email" },
    "me",
    CancellationToken.None
    new FileDataStore(ApplicationData.Current.LocalCacheFolder.Path, true));

the exception is gone. Now the execution thread just dies inside the AuthorizeAsync and I start getting the following error popup:

enter image description here

May answered 1/6, 2023 at 15:9 Comment(2)
Looks like you've solved the problem, you can accept this solution, it will be convenient for others with the same problem.Januarius
google apis doesn't support UWPCaveat
M
0

After some tried, I failed to make Google.Apis.Oauth2.v2 NuGet package v. 1.60.0.1869 to work with UWP. I made Google Login works by removing the NuGet and implementing OAuth flow myself as described in my answer here.

May answered 1/6, 2023 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.