Skip to content

Commit

Permalink
Update AADInternals.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sfonteneau authored Nov 15, 2024
1 parent ae9b975 commit b653a3b
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions AADInternals.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,32 @@ def get_token(self,scopes=["https://graph.windows.net/.default"]):
self.token_cache.has_state_changed = False
return token_response['access_token']

#https://github.com/Gerenios/AADInternals/blob/1561dc64568aa7c1a411e85d75ae2309c51d0633/GraphAPI_utils.ps1#L7
def call_graphapi(self,Command,select=''):

if select:
select = "?$select=%s" % select
response = requests.get(
f"https://graph.microsoft.com/v1.0/{Command}{select}",
headers={"Authorization": f"Bearer {self.get_token(['https://graph.microsoft.com/.default'])}"},
proxies=self.proxies,
verify=self.verify
)

return response.json().get('value', [])
def call_graphapi(self, Command, select='', top=100):
results = []
url = f"https://graph.microsoft.com/v1.0/{Command}"

if select or top:
query = []
if select:
query.append(f"$select={select}")
if top:
query.append(f"$top={top}")
url += "?" + "&".join(query)

while url:
response = requests.get(
url,
headers={"Authorization": f"Bearer {self.get_token(['https://graph.microsoft.com/.default'])}"},
proxies=self.proxies,
verify=self.verify
)
data = response.json()

results.extend(data.get('value', []))

url = data.get('@odata.nextLink')

return results


#https://github.com/Gerenios/AADInternals/blob/9cc2a3673248dbfaf0dccf960481e7830a395ea8/AzureADConnectAPI.ps1#L8
Expand Down

0 comments on commit b653a3b

Please sign in to comment.