denoland / deno_kv_oauth

High-level OAuth 2.0 powered by Deno KV.
https://jsr.io/@deno/kv-oauth
MIT License
246 stars 25 forks source link

Functions to list providers and other things #173

Closed jollytoad closed 1 year ago

jollytoad commented 1 year ago

I've been experimenting with deno_kv_oauth to provide a sign in for my personal site, I've created a handful of functions to discover available providers, and to dynamically configure providers based on the environment vars that have been set...

https://github.com/jollytoad/home/blob/main/lib/oauth2_clients.ts

Would you be interested in having some or all of these fns within deno_kv_auth itself? I'd be to raise a PR for this if so, and include some tests.

For an example of usage, see... https://github.com/jollytoad/home/blob/main/components/UserWidget.tsx This JSX component lists sign in links for providers where the env vars have been set, using getOAuth2ClientNames & hasOAuth2ClientEnvVars, the sign in link includes the provider name in the path, and https://github.com/jollytoad/home/blob/main/routes/auth/_lib/oauth2_client.ts has a function used by the signin/callback handlers to extract the provider name and use getOAuth2ClientFn & getOAuth2ClientScope. (All of this stuff is specific to my site though, so I wouldn't suggest incorporating these, I'm referencing them simply as an example of usage)

jollytoad commented 1 year ago

Here is an example of the UserWidget output btw...

UserWidget

The only changes I have to make to switch providers is to set the appropriate env vars, which is quite handy when working with Deno Deploy (my live site has no providers configured atm, it may do soon though).

iuioiua commented 1 year ago

I've always wanted to ensure that this module doesn't fall into the trap of doing too much and that its API surface is kept as small as possible. I'd prefer not to have these functions in the module for these reasons. However, you can still create your own module, which could be linked to in the README. I can see these functions having value in some edge cases.

jollytoad commented 1 year ago

Yeah, I totally understand. I'll let you know if I break them out into a dedicated module. I thought I should discuss the possibility first.