google.auth.exceptions.RefreshError:((使用域范围内的委托帐户的'access_denied:帐户受限']

问题描述 投票:0回答:1

我正在尝试在服务帐户上使用域范围的委派,以从admin sdk中获取一些信息以生成报告。我有一个已经正常工作的代码库,可以与gsuite域一起使用。我想使用相同的代码为另一个域生成报告,因此我为该另一个域设置了一个GCP项目。我创建了一个服务帐户,对其启用了域范围委派,并启用了该服务帐户的范围。当我尝试模拟任何域上的任何帐户的api调用时,出现以下错误

adminService.activities().list(userKey='all', applicationName='meet').execute()
google.auth.exceptions.RefreshError: ('access_denied: Account restricted', '{\n  "error": "access_denied",\n  "error_description": "Account restricted",\n  "error_uri":<url>}')

这是我用来创建服务的代码

credentials = service_account.Credentials.from_service_account_file(credentialsPath,
    scopes=['https://www.googleapis.com/auth/admin.reports.audit.readonly',
    "https://www.googleapis.com/auth/classroom.announcements.readonly",
    "https://www.googleapis.com/auth/classroom.courses.readonly",
    "https://www.googleapis.com/auth/classroom.coursework.students.readonly",
    "https://www.googleapis.com/auth/classroom.profile.emails",
    "https://www.googleapis.com/auth/classroom.rosters.readonly",
    "https://www.googleapis.com/auth/classroom.student-submissions.students.readonly",
    "https://www.googleapis.com/auth/classroom.topics.readonly"
    ])

    delegated_credentials = credentials.with_subject(email)

    return build('admin', 'reports_v1', credentials=delegated_credentials)

再次,这不应该是编程问题,因为相同的代码正在另一个域中工作,我认为我在admin / GCP配置端缺少了一些东西,但是我不知道是什么,而且我还没有在互联网上的任何地方都找不到此确切错误

python google-admin-sdk
1个回答
0
投票

事实证明,要使整个域的委托正常工作,您必须启用此功能

粗略地翻译为创建GCP项目的用户所属的组织单位上的“无需个人控制的附加服务”。您可以通过显示在管理面板中“应用程序”>“其他Google服务”页面顶部的工具提示来做到这一点]

© www.soinside.com 2019 - 2024. All rights reserved.