【发布时间】:2014-10-02 20:00:48
【问题描述】:
我们用 C# 开发应用程序,需要在未经原所有者许可的情况下将与窗帘域相关的所有 Google Drive 文档的所有权转移给单个特定用户。我们正在使用 Google Apps 企业帐户的试用版。
原则上,我们需要这样做:http://screencast.com/t/effVWLxL0Mr4 但在 C# 代码中。
根据文档,它在 OAuth2 中实现为超级管理员功能。 https://support.google.com/a/answer/1247799?hl=en (1)。 但是文档已被弃用,而且我们没有找到任何 API 调用来做到这一点。
使用项目创建者的帐户,显示他无法访问所有文件,也无法查看未与他共享的文件。
在管理 API 客户端访问的 Google 管理控制台中,我们为他添加了访问权限,以在未经许可的情况下访问文件。链接:screencast.com/t/zU9cc6Psyb。我们根据该文档链接添加了路由访问路由:trovepromo-tf.trove-stg.com/0m1-sds/support.google.com/a/answer/162106?hl=en 并再次尝试。 没有成功...
另外,我们发现我们需要使用服务帐户来访问域中所有用户的所有数据,因此我们在创建的项目中为服务帐户链接生成了 API 密钥:screencast.com/t/rNKuz6zchwV,并在应用程序使用以下代码:
var certificate = new X509Certificate2(@"C:\Temp\key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("Service account email")
{
User= "admin@domain.com",
Scopes = new[] { DriveService.Scope.Drive }
}.FromCertificate(certificate));
但是当我们尝试获取文件夹列表时,我们得到错误:“access_denied”,描述:"Requested client not authorized.", Uri:""
请帮助我们通过服务帐户将一位用户的所有权转让给另一位用户!
2014 年 8 月 13 日更新:
亲爱的,我的用户非个性化似乎有问题。
1)当我使用api代表用户连接时。在身份验证期间,它会重定向到浏览器并请求许可。在那之后一切都很好,我可以使用文件夹进行操作,除了一件事:我不能将所有权转让给他
2)当我使用没有非个性化的服务帐户时,身份验证如下所示:
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(ServiceAccountId)
{
Scopes = new[] { DriveService.Scope.Drive,
DriveService.Scope.DriveAppdata,
DriveService.Scope.DriveFile,
DriveService.Scope.DriveScripts,
DirectoryService.Scope.AdminDirectoryUser,
DirectoryService.Scope.AdminDirectoryGroup,
DirectoryService.Scope.AdminDirectoryOrgunit,
DirectoryService.Scope.AdminDirectoryUserReadonly
},
}.FromCertificate(certificate));
然后我可以访问共享到服务帐户的所有文件,但(再次)我无法转移权限。
3) 然后我尝试通过将 sypeadministrator 电子邮件帐户添加到用户 User = myaddress@mydomain.com 来非个人化服务帐户
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(ServiceAccountId)
{
Scopes = new[] { DriveService.Scope.Drive,
DriveService.Scope.DriveAppdata,
DriveService.Scope.DriveFile,
DriveService.Scope.DriveScripts,
DirectoryService.Scope.AdminDirectoryUser,
DirectoryService.Scope.AdminDirectoryGroup,
DirectoryService.Scope.AdminDirectoryOrgunit,
DirectoryService.Scope.AdminDirectoryUserReadonly
},
User = AdminEmail,
}.FromCertificate(certificate));
然后我有错误:“access_denied”,描述:“请求的客户端未授权。”,Uri:“”
如何正确非个性化服务帐户?
2014 年 8 月 13 日更新
我们发现认证的基本api在这里:https://developers.google.com/accounts/docs/OAuth2ServiceAccount#creatingjwt
通常,我之前展示的只是协议的 .net 实现。
我们如何在 .net 代码中对用户进行非个性化处理。我们没有找到任何有效的 .net 实现。
【问题讨论】:
-
当您尝试获取访问权限时,您会转到 google 页面进行用户身份验证。您是否看到获得“驱动器”权利的选项?
-
亲爱的,我无法在这里回答您的问题,但我更新了我的问题。能否请您查看 2014 年 8 月 13 日的更新。
标签: c# .net oauth-2.0 google-drive-api oauth2client