mvertopoulos / vue-msal

Vue plugin for using Microsoft Authentication Library (MSAL)
MIT License
123 stars 66 forks source link

msGraph - post|update requests #41

Open m0jimo opened 3 years ago

m0jimo commented 3 years ago

$msal works great for me with Graph connections to get data from Sharepoint.

But is there a way how to send a Graph post request or at least to use client for Graph post and update request?

Thanks.

jadjare commented 3 years ago

I ran into the same problem and overcome it by making a my own post request, in my case by using the Axios library.

I needed to check if a user was a member of a group and achieved this using the onToken callback parameter.

Below is a simplified example

Vue.use(msal,
    {

        auth: {
            authority: `https://login.microsoftonline.com/${process.env.VUE_APP_AZURE_ACTIVE_DIRECTORY_TENANT_ID}`,
            clientId: process.env.VUE_APP_AZURE_STORE_CLIENT_APPLICATION_ID,
            redirectUri: `${window.location.origin}/login`,

            onToken: (ctx) => {
                        const groupIds = {groupIds: []}//Group Id's retrieved from config
                        axios.post(`https://graph.microsoft.com/v1.0/directoryObjects/${ctx.account.accountIdentifier}/checkMemberGroups`,
                            { groupIds },
                            { headers: {
                                authorization: `bearer ${ctx.data.accessToken}`,
                                "access-control-allow-methods": "[POST]",
                                Accept: "application/json",
                                "Content-Type": "application/json"
                            }
                            }).then(response => {
                                const groups = response.data.value;
                                //Add the groups to the user stored in Vuex
                            });
                    }
                }
            })
l3miage-serzhann commented 2 years ago

$msal works great for me with Graph connections to get data from Sharepoint.

But is there a way how to send a Graph post request or at least to use client for Graph post and update request?

Thanks.

Actually you can add the configurations in your request .Like this: $msal.msGraph({url:'https://graph.microsoft.com/v1.0/me/events',method:'POST',data:getters.getItem}) I use Vuex store here ,dont be confused