Introducing OAuth integration! #192
pilcrowonpaper
announced in
Announcements
Replies: 2 comments 4 replies
-
wouldnt be better to import the environment variables from i remember reading something about these |
Beta Was this translation helpful? Give feedback.
1 reply
-
This looks great, is a Facebook provider in the pipeline, or something that you want to be contributed? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
We're just shy of 400 Github stars and I'm pleasantly surprised with how fast this project is growing. Thank you!
Today, I'm happy to introduce OAuth integration for Lucia! OAuth has been one of those thing that isn't critical enough for it to be part of the core library, but is still very important and kinda unnecessarily annoying. The great thing about Lucia is how simple and extendable it is, and I think the OAuth integration shows that. You start with something simple and flexible, and you optionally add features on top of it.
So how does it work? Using Github OAuth as an example, you first import the Github provider:
You can get the authorization url with
getAuthorizationUrl()
. This is the url you want to redirect the user to when they click "Sign in with Github." This will also createstate
, which should be stored in a httpOnly cookie and is used to verify the callback.After signing in, Github will redirect the user back to your site. To handle the callback, get the code and state from the search params. Make sure the state matches the one stored in the cookie and use
validateCallback()
. This will validate the code for you and return both the Github user and, if it exists, the corresponding user in your database. If it doesn't exists, you can create the user usingcreateUser()
method.We currently only provide Github and Google, but I'm happy to add more.
To start using it, install the package:
Documentation is here: https://lucia-auth.vercel.app/oauth/start-here/getting-started
Beta Was this translation helpful? Give feedback.
All reactions