Access to path c:\users is denied.

huangapple go评论52阅读模式
英文:

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

问题

在将Google.Apis.Oauth2.v2 NuGet包升级到版本1.60.0.1869后,当尝试在我的UWP应用程序中使用Google登录时,我开始收到异常拒绝访问路径C:\Users。以下是我的代码:

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

异常发生在GoogleWebAuthorizationBroker.AuthorizeAsync调用中。

这段代码(稍作更改)在使用Google.Apis.Oauth2.v2包版本1.25.0.859之前运行良好,但现在此包已过时且不再起作用。

如何在我的UWP应用程序中使用Google登录?

注意:我明白UWP应用程序无法访问c:\Users,但我的代码从未请求该文件夹中的任何内容。google_client_secrets.json存在,我可以从流中读取它,因此该文件与问题无关。

更新

在我将AuthorizeAsync的第5个参数设置为以下内容后:

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

异常消失了。现在,执行线程只是在AuthorizeAsync内部终止,并出现以下错误弹窗:

Access to path c:\users is denied.

英文:

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:

Access to path c:\users is denied.

答案1

得分: 0

经过一些尝试,我未能使 Google.Apis.Oauth2.v2 NuGet 包版本 1.60.0.1869 在 UWP 中工作。我通过移除 NuGet 并按照我在这里回答中描述的方式自己实现了 Google 登录功能。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月1日 23:09:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定