[英]Could not find a part of the path 'C:\\Windows\\System32\\oobe\\info\\Backgrounds
[英]Access to the path 'C:\Windows\system32\config\systemprofile' is denied when using Google.Api OAuth 2
我正在使用Google Calendar Api
和我的一个项目。 我不知道如何,但下面显示的错误是令人不安的。
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; }
}
}
我试过GitHub下面的解决方案但是没有用
以上解决方案对我没有用,如果有任何答案请帮忙。
根据https://domantasjovaisas.wordpress.com/2014/09/27/demystifying-google-api-and-oauth2/ :
从我刚提供的代码中你可以看到我正在使用File2DataStore。 它被我超越了。 标准FileDataStore我改变了我自己的需求。 标准FileDataStore将身份验证密钥存储在“C:\\ WINDOWS \\ system32 \\ config \\ systemprofile \\ AppData \\ Roaming \\ Drive.Api.Auth.Store”中
我不认为你会允许IIS_IUSRS用户在生产环境中访问这个位置🙂三思而后行,不要这样做。 根据您自己的需要重写FileDataSource。 以下是两个如何做到的例子:
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
简而言之,您需要停止使用FileDataStore
并编写自己的替换(使用上面的链接作为起点)。
问题是默认情况下
new FileDataStore("Calendar.Api.Auth.Store")
将数据存储在需要特殊权限的路径中,因此将完整路径作为参数发送。
代替
new FileDataStore("Calendar.Api.Auth.Store")
例如,将完整路径发送到要保存在文件系统中的位置,将第二个参数设置为true
new FileDataStore(fullpath, true);
这应该工作。 祝好运
我不知道谷歌API ...但该文件夹具有特定的安全性,只允许访问Administrators
组成员。
也许用户(由IIS或Visual Studio使用)必须是本地计算机Administrator
组(\\ Administrator)的成员。
顺便说一下,在Visual Studio中,您必须以管理员身份启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.