denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.26k stars 630 forks source link

Oauth2 in Fresh? #688

Closed wongataa closed 1 year ago

wongataa commented 2 years ago

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

lino-levan commented 2 years ago

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.

digitaldesigndj commented 2 years ago

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.

wongataa commented 2 years ago

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

omar2205 commented 2 years ago

Check this library https://github.com/w3cj/deno_grant/

afifurrohman-id commented 1 year ago

Using official deno kv https://github.com/denoland/deno_kv_oauth

maintenance by deno team

deer commented 1 year ago

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.