microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
942 stars 300 forks source link

Support headers in mgt-get #653

Open beth-panx opened 4 years ago

beth-panx commented 4 years ago

Proposal: Add support for headers in mgt-get

Description

To support api's such as List users beta

Rationale

There are times graph api supports passing of additional headers. Right now mgt-get doesn't have this as an option. Developer will need to overwrite the graph client to achieve this.

Preferred Solution

Add header attribute or property

ghost commented 4 years ago

Hello beth-panx, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

MrCodeWeaver commented 3 years ago

@beth-panx @shweaver-MSFT I would like to use mgt-get to get the manager chain up to the root level https://docs.microsoft.com/en-us/graph/api/user-list-manager?view=graph-rest-1.0&tabs=http#example-2-get-manager-chain-up-to-the-root-level, and that requires ConsistencyLevel: eventual be sent in the request headers. This is a feature I want to see!

nmetulev commented 3 years ago

Agree, this features would make the component much better. What do you think about adding the header property like so:

<mgt-get resource="bla" headers="key:value, key:value" />

I believe this should be fairly straightforward to implement?

MrCodeWeaver commented 3 years ago

That would be fine!

nmetulev commented 3 years ago

Another reference: https://stackoverflow.com/questions/67766620/microsoft-graph-toolkit-mgt-how-do-i-modify-add-request-headers-for-the-mgt

anthem89 commented 1 year ago

I am not an expert in this, so apologies if this isn't what you are asking about. I found that if you are using the providers built into the toolkit, you can simply do something like this to add request headers to all mgt-get component requests without having to re-initialize the graph client and re-create the middleware chain:

Providers.globalProvider.graph.client.config.fetchOptions = {headers: {'Prefer': 'IdType="ImmutableId"'}}

(obviously change the request headers to whatever you want)

I should also note, you can even do this after the provider has been initialized. Any subsequent calls after you set the fetchOptions will include the headers in the request.

Also, if you are loading the provider via a HTML provider component tag like this for example: <script src="https://unpkg.com/@microsoft/mgt@2/dist/bundle/mgt-loader.js"></script> <mgt-msal2-provider client-id="YOUR_CLIENT_ID"></mgt-msal2-provider>

You can access the globalProvider object like this:

mgt.Providers.globalProvider.graph.client.config.fetchOptions = {headers: {'Prefer': 'IdType="ImmutableId"'}}

sebastienlevert commented 1 year ago

You are absolutely right. This works, but will impact all future calls. I think a more sustainable solution would be a way to provide headers on the component itself, but it's a great workaround while we figure out a good way to bring this feature.

FYI @gavinbarron

sebastienlevert commented 8 months ago

Related to #1723