mvertopoulos / vue-msal

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

POST-based graph APIs are not supported #3

Closed Agendum closed 5 years ago

Agendum commented 5 years ago

I would like to use the graph APIs exposed via vue-msal, but it doesn't support POST-based APIs. For example, the /me/getMemberGroups API (to check for group membership) is a POST-only API, and even has a required body. The current APIs in vue-msal are hard-coded to GET-only:

    createRequest(endpoint, index = 0) {
        const request = {
            url: '',
            method: 'GET',
            id: `defaultID-${index}`
        };
        endpoint = this.getEndpointObject(endpoint);
        if (endpoint.url) {
            Object.assign(request, endpoint);
        }
        else {
            throw ({ error: 'invalid endpoint', endpoint: endpoint });
        }
        return request;
    }

It would also be nice to do this with the "callAfterInit" feature as well.

mvertopoulos commented 5 years ago

The code I believe you are referring to, is just setting the defaults, which are then overwritten with Object.assign().

Try this:

graph: {
  callAfterInit: true,
  endpoints: {
    // profile: '/me',
    memberGroups: { url: '/me/getMemberGroups', method: 'POST', data: { securityEnabledOnly: true } }
  }
}

Please check the relevant section of the documentation for details on how to call the msGraph function and what arguments it accepts. Also as mentioned there, the configuration extends from Axios Request Configuration, so you can add any other options you want for your case (hence the data property).

Let me know if that works for you.

Agendum commented 5 years ago

Ah I completely missed both the 'Object.assign' in the code which I pasted above. Also I missed the Axios comment as well. Sorry for the noise! And thanks for making vue-msal!