Following the Connect to Azure AD-secured APIs in SharePoint Framework solutions tutorial, once SPFx handled the authentication of the current user to my Function App, I would simply like to get an access token which I could use to open a ClientContext with and perform operations in SharePoint Online on behalf of the user.
I was able to create with success an SPFx extension which authenticates and calls my Azure Function using the AadHttpClient, so far so good. In my C# Azure Function, I can trace the current user's name and I do see the current user correctly, so the whole SPFx / AAD App / Azure Function authentication process works as expected.
The only step I am missing is to open a CSOM ClientContext using the currently logged in user. There is no official documentation on this whatsoever, I expected the bearer token to be available in the function's parameters but it doesn't look as easy.
The article above does not cover the azure side at all, it only shows the JavaScript side...
Any help would be appreciated, thanks!
Closing this issue, after digging and digging I finally managed to find the article below which pin points pretty much exactly what I was trying to do :
https://www.vrdmn.com/2018/05/spfx-calling-back-to-sharepoint-from.html
Basically the token available in the function's headers is the token sent by SPFX when authenticating to the azure function, however this token CANNOT be used to call SharePoint. You have to request another token, based on the previous token, to then be able to call SharePoint with it...
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues
Most helpful comment
Closing this issue, after digging and digging I finally managed to find the article below which pin points pretty much exactly what I was trying to do :
https://www.vrdmn.com/2018/05/spfx-calling-back-to-sharepoint-from.html
Basically the token available in the function's headers is the token sent by SPFX when authenticating to the azure function, however this token CANNOT be used to call SharePoint. You have to request another token, based on the previous token, to then be able to call SharePoint with it...