graphrbac_client = GraphRbacManagementClient(
credentials = ServicePrincipalCredentials(
client_id = CLIENT,
secret = KEY,
tenant = TENANT_ID,
resource = "https://graph.windows.net"
),
TENANT_ID
)
for sp in graphrbac_client.service_principals.list():
if sp.app_id == graphrbac_client.config.credentials.id:
print('found it')
它可以工作,但对应用程序要求太多权限(我只设法让它与Directory一起工作。ReadAll不与Directory一起工作
Application.ReadWrite.All
,出于某种原因)。我找到的所有方法似乎都需要预先了解objectId。。。这正是我想要找回的。
使用
this
def resolve_service_principal(identifier):
"""Get an object_id from a client_id.
"""
graphrbac_credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID'],
resource="https://graph.windows.net"
)
graphrbac_client = GraphRbacManagementClient(
graphrbac_credentials,
os.environ['AZURE_TENANT_ID']
)
result = list(graphrbac_client.service_principals.list(filter="servicePrincipalNames/any(c:c eq '{}')".format(identifier)))
if result:
return result[0].object_id
raise RuntimeError("Unable to get object_id from client_id")