pnp / graph-connectors-samples

Microsoft Graph Connector samples
https://aka.ms/gc/samples
MIT License
41 stars 32 forks source link

GraphDocsConnector - Call API endpoint with Authorization Bearer Key #58

Open Anil-Raju-SHC opened 2 weeks ago

Anil-Raju-SHC commented 2 weeks ago

Hi Waldek Mastykarz & Garry Trinder, I appreciate your Custom Graph Connector sample -GraphDocsConnector.

I was able to able to successfully build your sample solution and push it to our test environment and its working flawless.

As part of the real world implementation, I need to call an API endpoint which expects Authorization header with Bearer string, I dont see that being implemented as part of the working sample.

Would you please help me guide on how to implement calling the API endpoints with accepts the Authorization header or enhance the sample solution with authorization header?

Thanks, Anil

waldekmastykarz commented 2 weeks ago

Hey @Anil-Raju-SHC! Thanks for reaching out and kind words! Is the API that you need to call secured with Entra or another identity provider (IdP)? If so, is it in the same tenant as your Graph connector or another?

Anil-Raju-SHC commented 2 weeks ago

Hi Waldek, We are trying to add external data source content from third party website.

We are trying to call the API endpoint (https://partner.socialchorus.com/endpoints/#/Content%20Publishing/listContent) built by social chorus and they are not maintained or hosted on our servers so they are not on the same tenant as our graph connector and I am not sure what IdP they are using to secure the API.

We first generate the authorization token by calling this API endpoint https://auth.socialchorus.com/oauth/token by providing Client ID and Client Secret, once the authorization token is generated and then we use that token to call https://partner.socialchorus.com/v2/content API endpoint to get all the content which needs to be ingested and the ingested contents should be shown in the M360 search results.

I am not sure how to have this implemented, please help. A working solution with this kind of API call would be greatly appreciated, please let me know if you need additional information.

Thanks, Anil

waldekmastykarz commented 2 weeks ago

Have you seen their auth guidance here: https://partner.socialchorus.com/authorization?

Anil-Raju-SHC commented 2 weeks ago

Hi Waldek, Yes, I did check their guide and they recommend to generate the access token using the Client ID and Client Secret and then use the generated access token to call their API endpoint.

Is there any working sample for Custom Graph Connector in C# which can generate the access token by calling specific API with provided Client ID and Client Secret and then use that token to make an API call to get the content and then ingest that content?

or

A simpler working sample in C# which can just make an API call by providing the Authorization token to get the content and then ingest that content?

Any help in the right direction would be greatly appreciated.

Thanks!

waldekmastykarz commented 2 weeks ago

I don't think we have any sample that shows auth at the moment. That said, even if we had, I wonder how useful it would be, given that how you get a token varies per API provider. What's more, many API providers offer SDK that abstracts getting the token away, which would make the sample useless for you, unless it would use the exact same API that you're trying to use.

Looking at their docs, they explain the exact web requests that you need to do to get a token. Have you tried following the steps outlined in the documentation?