Unauthorized Microsoft Graph API Add member in group.

Highlighted
Occasional Contributor

Hello,

 

I am using Microsoft Graph API in my SPFx website. I can successfully get accessToken using ADAL.js. I can create user, get users, get groups but when i am trying to add memebrs in group it throws error of Unauthorized.

 

I had assiged full permission to app resource and my signed in user is global administrator.

 

With graph explorer same request is working fine.

 

All parameters value passes are true that i have verified.

 

private AddUserInGroup(httpClient: HttpClient, accessToken: string, objUser: IUser, groupId: string): Promise<boolean> {
return new Promise<boolean>((resolve: (isAdded: boolean) => string, reject: (error: string) => string): void => {
httpClient.post("/groups/" + groupId + "/members/$ref", HttpClient.configurations.v1, {
headers: {
'Content-type': 'application/json',
'Authorization': 'Bearer ' + accessToken
},
body: "{ \"@odata.id\": \"https://graph.microsoft.com/v1.0/users/" + objUser.id + "\"}"
})
.then((response: HttpClientResponse): void => {
debugger;
if (response.ok)
resolve(true);
else
reject(response.statusText);
}), (error: any): void => {
debugger;
alert(error.message);
if (error.message.toLowerCase() == "failed to fetch")
resolve(true);
else {
alert("Error : " + error.message);
reject(error.message);
}
};
});
}
 
If anyone knows answer then please let me know. Thanks in advance.
2 Replies
Highlighted
Highlighted

I read it and it seems that it will not work with Internet Explorer and mixed zones.

 

I can able to get accessToken and can run other apis successfully except Add members in group so do you think that it is related to adal.js (mixed zones).

 

Can you confirm that whether it will work or not?

 

If not then can you provide alternative solution for it. As i want to develop one functionality which requires this features.

 

Thanks for your prompt reply.