To resolve this issue create Azure AD Application and granted API permissions Group.Read.All, User.Read, User.Read.All in delegated reference.
Get Delegated Access toke Refer to this document for more details: https://learn.microsoft.com/en-us/graph/auth-v2-user#3-get-a-token
Sample:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id:ClientID
grant_type:authorization_code
code:code
redirect_uri:https://jwt.ms
client_secret:ClientSecret
scope:https://graph.microsoft.com/.default
Now use the access token which you got from the above into the below Graph API endpoint
GET https://graph.microsoft.com/v1.0/users/UserID/memberOf
Reference documentation: https://learn.microsoft.com/en-us/graph/api/user-list-memberof?view=graph-rest-1.0&tabs=http
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.