subhendukundu / worker-auth-providers

worker-auth-providers is an open-source providers to make authentication easy with workers. Very lightweight script which doesn't need a lot of dependencies. Plug it with any framework or template of workers.
https://authc1.com
293 stars 31 forks source link

How to specify for {provider} to return a refresh_token? #46

Open Darko opened 5 months ago

Darko commented 5 months ago

First of all, great library! Think I've gone bald trying to figure out google auth from inside a worker.

2nd, when I perform the auth flow, google does not return a refresh_token alongside the id_token and the rest of the payload. How would I go about specifying that I want a refresh token to be returned?

plutonium-239 commented 1 month ago

Hi

42 had fixed this but there is no way to access it directly because there have been no new releases since an year.

This adds an accessType to the options while calling redirect. By default this is set to online, which doesn't return a refresh token. You can set it to offline to make it return one.

Ultimately,

await google.redirect({
    options: {
         ...
+        accessType: "offline"
    }
});

As a workaround, you can do

npm install git+https://github.com/subhendukundu/worker-auth-providers.git

to manually build the latest version from github. Note that you will need yarn and git, although only for the build process.