AleksandrRogov / DynamicsWebApi

DynamicsWebApi is a Microsoft Dataverse Web API helper library for JavaScript & TypeScript
MIT License
272 stars 59 forks source link

Add __RequestVerificationToken header for Portals Web API auth #157

Closed 03-CiprianoG closed 1 year ago

03-CiprianoG commented 1 year ago

Hey @AleksandrRogov, hope u're doing great :).

As you correctly made me notice form last PR, we would need a __RequestVerificationToken header to comply with the Portals Web API auth.

I kind of "analyzed" the composition flow of the request and I came up with this integration which should add as little code as possible and it works seamlessly with the rest of the lib.

Of course you can suggest another place to put this bit of code if you will, let me know ;).

Thanks, have a nice one 🫡

AleksandrRogov commented 1 year ago

hi @03-CiprianoG , Thank you for the PR. Are you certain that this will work, did you test it on the portal? as I understand shell.getTokenDeferred(); returns a jQuery.deferred object which is not a promise implementation that browsers have. by looking at the implementation of that getTokenDeferred function it should be possible to implement a similar function, probably in the Utility class but the one that will use the browser's promise implementation.

Though, I haven't tried using jQuery with async/await, so I may be wrong.

P.S. Doing well, thanks for asking!

03-CiprianoG commented 1 year ago

Hey @AleksandrRogov, I tested it and it works fine 👍🏽

AleksandrRogov commented 1 year ago

@03-CiprianoG awesome, thank you!

I see that the Power Pages use v.3.6+ of jQuery and I found the release notes for v.3.0 where the jQuery team say that they have implemented Promises/A+ and ES2015 Promises to be compatible with modern standards, which is great, I did not know that. +1 to jQuery :)

For reference: https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/