是否可以授权公共云中的应用通过图API从政府租户获取数据?

时间:2020-10-06 16:04:49

标签: azure-gov

我正试图通过图形api从政府租户那里获取电子邮件列表,并且直到上周都工作良好。我正在使用客户端凭据流。上周,我尝试在政府租户中授权我的应用程序时开始出现以下错误:

oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) AADSTS900441: Requests to applications hosted in the public cloud are not supported for USGov tenants.

是否有一种方法可以授权来自公共天蓝色云的应用程序读取政府租户的数据?

编辑:代码示例和调试日志

    from oauthlib.oauth2 import BackendApplicationClient
    
    client = BackendApplicationClient(client_id=config.CLIENT_ID)
    MSGRAPH = requests_oauthlib.OAuth2Session(
        client=client
    )
    
    token = MSGRAPH.fetch_token(
        'https://login.microsoftonline.us' + '/<tenant>' + config.TOKEN_ENDPOINT,
        client_id=config.CLIENT_ID,
        client_secret=config.CLIENT_SECRET,
        include_client_id=True,
        scope=['https://graph.microsoft.us/.default'])

    endpoint = config.RESOURCE + config.API_VERSION + '/users'
    graphdata = MSGRAPH.get(endpoint).json()
DEBUG:requests_oauthlib.oauth2_session:Requesting url https://login.microsoftonline.us/<tenant-id>/oauth2/v2.0/token using method POST.
DEBUG:requests_oauthlib.oauth2_session:Supplying headers {u'Content-Type': u'application/x-www-form-urlencoded;charset=UTF-8', u'Accept': u'application/json'} and data {u'client_secret': u'...', u'grant_type': u'client_credentials', u'client_id': u'...', u'scope': u'https://graph.microsoft.us/.default'}
DEBUG:requests_oauthlib.oauth2_session:Passing through key word arguments {'verify': True, 'json': None, 'proxies': None, 'timeout': None, 'auth': None}.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): login.microsoftonline.us:443
DEBUG:urllib3.connectionpool:https://login.microsoftonline.us:443 "POST /<tenant-id>/oauth2/v2.0/token HTTP/1.1" 400 522
DEBUG:requests_oauthlib.oauth2_session:Prepared fetch token request body grant_type=client_credentials&client_id=...&client_secret=...&scope=https%3A%2F%2Fgraph.microsoft.us%2F.default
DEBUG:requests_oauthlib.oauth2_session:Request to fetch token completed with status 400.

基本上,当我尝试获取访问令牌时会看到此错误。租户管理员已经向我的应用程序提供了管理员同意。 这段代码为政府租户工作了一个月左右,然后突然停止工作。

1 个答案:

答案 0 :(得分:1)

AAD大约在一个月前开始执行此操作,GCC高级别/国防部租户无法使用在商业云中发布的机密应用。您需要从GCC高级/国防部租户发布您的应用。

相关问题