fresh
fresh copied to clipboard
Oauth2 in Fresh?
Hey, I'm new to Deno and Fresh, but was hoping to get my feet wet with an oauth application. I found several frameworks that work with Oak[1][2], but none with Fresh. I saw Fresh has removed its Oak dependencies and I can't see how I would use either framework. Is there another option?
Thanks for your work with Fresh; it looks great
[1] https://bedrockauth.dev/docs.html [2] https://github.com/oslabs-beta/dashport
I'd probably recommend using something like the third party oauth2 module. It's a more annoying to set up than a more opinionated setup but it will theoretically work for whatever you're trying to do.
https://deno.land/x/oauth2
It would be cool to see a first-party/opinionated offering from fresh though.
I use a strapi backend, so I have setup my OAuth there pasting keys in.
Then my fresh sites can use that API for OAuth. Here's a basic example:
The initial redirect to start the login process: https://github.com/Hyprtxt/fresh-strapi.deno.dev/blob/main/routes/login/%5Bprovider%5D.js
The callback route: https://github.com/Hyprtxt/fresh-strapi.deno.dev/blob/main/routes/api/%5Bprovider%5D/auth.js
Here's a working example: https://fresh-strapi.deno.dev/login It's just currently using another projects config, so the consent screen is wrong (videopoker.academy).
The backend is completely proxied away from the users this way. It's not OAuth done 'in deno" as strapi is node and uses grant. But it is effective for me.
thanks to you both for your quick comments and pointers. I'll check both options out and run with one.
@digitaldesigndj cheers for the extensive details you've included too
Check this library https://github.com/w3cj/deno_grant/
Using official deno kv https://github.com/denoland/deno_kv_oauth
maintenance by deno team
This should also be closed now that we have documentation for using deno_kv_oauth
as well: https://fresh.deno.dev/docs/examples/using-deno-kv-oauth.