Azure-Samples / ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
284 stars 135 forks source link

graph.microsoft getting Groups #62

Closed nfoley84 closed 3 years ago

nfoley84 commented 3 years ago

Using OAUTH2 with the following:

microsoft = oauth.remote_app(
        'microsoft',
        consumer_key='{}'.format(consumerkey),
        consumer_secret='{}'.format(consumersecret),
        request_token_params={'scope': 'offline_access User.Read'},
        base_url='https://graph.microsoft.com/v1.0/',

I can a query for groups that the logged-in User is Part of

displayName = microsoft.get('me?$select=displayName')
userName = displayName.data['displayName']
GroupName = micosoft.get('me//transitiveMemberOf/microsoft.graph.group?$select=displayName')
{Loop Over GroupName} < Append to List

Using MSAL how can this be done using the /Users Endpoint? I changed the app_config.py to

ENDPOINT = 'https://graph.microsoft.com/v1.0/me'

But only able to get the Email or Display Name showing

preferredUsername = user=session['user']['displayName'] # Getting User from User.Session

rayluo commented 3 years ago

I haven't used the OAUTH2 library you mentioned, but based on observation to your code snippet, my guess is its group query would be https://graph.microsoft.com/v1.0/me//transitiveMemberOf/microsoft.graph.group or https://graph.microsoft.com/v1.0/me//transitiveMemberOf/microsoft.graph.group?$select=displayName. You can try setting either of them as the ENDPOINT, and see how it goes.

rayluo commented 3 years ago

Closing due to inactivity.