DEV Community

Sam Watkins
Sam Watkins

Posted on

OAuth2 examples for Deno

I'm working on creating some "portfolio pieces" that are useful web apps. The first project is a kanban board system, similar to Trello with a bit of Airtable mixed in, and my own ideas.

I decided to use Svelte kit and Tailwind CSS on the front-end, but I'm having a bit of trouble settling on a good system for authentication.

I started out using Django REST and Djoser, but I'm experiencing some difficulties with this, and I'm thinking it would be better to use something lighter for the public facing auth server.

Firebase auth would be an easy way to get things up and running. Unlike other auth-as-a-service providers, Google allows unlimited use of Firebase auth free of charge (except for cellular text messages, which are limited). This would be the most practical option, I suppose.

In the Python world, Flask and FastAPI are more performant, lighter frameworks. The FastAPI Users module looks like a good option for authentication.

However, today I had a bit of a "JavaScript everywhere" mood, with the idea to share some code on the client and server, including validation. So I did a little work towards setting up an OAuth2 authentication server in Deno.

I tried two libraries, Dashport and deno-oauth2-client.

Dashport aims to be like Passport.js for Deno. I had a bit of trouble getting their example code to work, so I forked the repo, fixed a few bugs and added some example code. I also posted a slightly more developed example. In the process, I gained a bit more experience with TypeScript.

The other module, deno-oauth2-client, works well. It's smaller and easy to use. Their example shows how to do GitHub auth. I extended the example to support Google and Facebook auth also.

There's a ways to go before this will be useful as an authentication server. As it is, I can prompt the user to log in with those providers, and fetch the user info.

I would also like to find or put together a good "local login" system, with email and password auth, also email confirmation, password reset, and all the customary features. I'm not sure if I'll continue with Deno for this, or explore other options.

Auth is pretty dull, but I guess it will be useful to have a good system that I can reuse in future. Probably should just use Firebase. Anyway, worst case scenario I'm learning stuff that can be useful in future.

Top comments (0)