openid / AppAuth-JS

JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Apache License 2.0
977 stars 162 forks source link

Drop JQuery requirement for Web Apps #88

Closed aberasarte closed 5 years ago

aberasarte commented 5 years ago

I'm using this library in an SPA for connecting with an OIDC provider using the Authorization code flow with PKCE. It works flawlessly but it assumes that jQuery has being loaded in the browser failing otherwise.

Looking at the code, I think that JQuery is being used just for sending AJAX requests. I really want to avoid JQuery as it's a huge library and we are not using it for anything else. Probably, the JQuery AJAX calls could be replaced by just XMLHttpRequest calls.

WDYT? I could start a PR.

tikurahul commented 5 years ago

Sorry about the delay in replying. I think this came up in another issue (although I am not able to find it at the moment). AppAuth-JS does not actually have a strict dependency on jQuery other than the typings itself. fetch has typings too, but assumes a lot of things are global - so it does not work equally well as an interface.

We already have a notion of a Requestor which JQueryRequestor happens to implement. It would be easy enough to implement a FetchRequestor which uses fetch under the hood while honoring the same interface. I was going to write one, but if you want to take a stab, send me a PR and I can take a look.

aberasarte commented 5 years ago

Thanks @tikurahul.

My bad. I didn't see that both the fetchFromIssuer method and the BaseTokenRequestHandler constructor, can optionally receive a requestor implementation that would be used for making the requests instead of the jQuery based one.

I'm closing the issue and I would send a PR later with a FetchRequestor proposal.

tikurahul commented 5 years ago

Published AppAuth-JS 1.2.0 with the FetchRequestor.