-
-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5cbf80
commit a03e7d2
Showing
67 changed files
with
2,904 additions
and
2,191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "minor" # "major", "minor", "patch" | ||
--- | ||
|
||
Experimental API `createOAuth2AuthorizationUrl()`, `createOAuth2AuthorizationUrlWithPKCE()`, `validateOAuth2AuthorizationCode()`, and `decodeIdToken()` are now stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "minor" # "major", "minor", "patch" | ||
--- | ||
|
||
Update `createOAuth2AuthorizationUrlWithPKCE()` return type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "major" # "major", "minor", "patch" | ||
--- | ||
|
||
Remove `generateState()` export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "major" # "major", "minor", "patch" | ||
--- | ||
|
||
Replace `OAuthProvider` with `OAuth2ProviderAuth` and `OAuth2ProviderAuthWithPKCE` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "major" # "major", "minor", "patch" | ||
--- | ||
|
||
Replace `GithubProvider` with `GithubAuth` etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "minor" # "major", "minor", "patch" | ||
pull: "1005" | ||
--- | ||
|
||
Add Azure Active Directory provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "minor" # "major", "minor", "patch" | ||
--- | ||
|
||
Remove `options.searchParams` and `options.state` from `createOAuth2AuthorizationUrl()` and `createOAuth2AuthorizationUrlWithPKCE()` params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
package: "@lucia-auth/oauth" # package name | ||
type: "major" # "major", "minor", "patch" | ||
--- | ||
|
||
Update `auth0()`, `google()`, `patreon()`, `reddit()`, `spotify()`, `twitch()` params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 0 additions & 141 deletions
141
documentation/content/oauth/basics/built-in-providers.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: "Handle users with Lucia" | ||
description: "Learn how to use the built-in OAuth 2.0 providers" | ||
--- | ||
|
||
After authenticating the user with OAuth, you can get an existing or create a new Lucia user using [`ProviderUserAuth`](/reference/oauth/interfaces/provideruserauth). If you're using one of the built in providers, [`OAuth2ProviderAuth.validateCallback()`](reference/oauth/interfaces/oauth2providerauth#validatecallback) and [`OAuth2ProviderAuthWithPKCE.validateCallback()`](reference/oauth/interfaces/oauth2providerauthwithpkce#validatecallback) will return a provider-extended instance of it. | ||
|
||
```ts | ||
import { github } from "@lucia-auth/oauth/providers"; | ||
|
||
const githubAuth = github(); | ||
const githubUserAuth = githubAuth.validateCallback(); | ||
``` | ||
|
||
Alternatively, if you're using one of the OAuth helpers, you can use [`providerUserAuth()`](/reference/oauth/modules/main#provideruserauth) to manually create a new instance of it. It takes your Lucia `Auth` instance, the provider id (e.g. `"github"`), and the provider user id (e.g. Github user id). | ||
|
||
```ts | ||
const githubUserAuth = providerUserAuth(auth, "github", githubUserId); | ||
``` | ||
|
||
## Basic usage | ||
|
||
[`ProviderUserAuth.getExistingUser()`](/reference/oauth/interfaces/provideruserauth/#getexistinguser) will return a `User` if a Lucia user already exists for the authenticated provider account. This is based on the provider user id (e.g. Github user id) and not shared identifiers like email. | ||
|
||
If not, you can create a new Lucia user linked to the provider with [`ProviderUserAuth.createUser()`](/reference/oauth/interfaces/provideruserauth#createuser). You can get the provider user data with `githubUser` for Github, etc. | ||
|
||
```ts | ||
const getUser = async () => { | ||
const existingUser = await githubUserAuth.getExistingUser(); | ||
if (existingUser) return existingUser; | ||
// create a new user if the user does not exist | ||
return await githubUserAuth.createUser({ | ||
attributes: { | ||
githubUsername: githubUser.login | ||
} | ||
}); | ||
}; | ||
const user = await getUser(); | ||
|
||
// login user | ||
const session = await auth.createSession({ | ||
userId: user.userId, | ||
attributes: {} | ||
}); | ||
const authRequest = auth.handleRequest(); | ||
authRequest.setSession(session); // store session cookie | ||
``` | ||
|
||
## Add a new key to an existing user | ||
|
||
Alternatively, you may want to add a new authentication method to an existing user. Calling [`ProviderUserAuth.createKey()`](/reference/oauth/interfaces/provideruserauth#createkey) will create a new key linked to the provided user id. | ||
|
||
```ts | ||
const existingUser = githubUserAuth.getExistingUser(); | ||
if (existingUser) { | ||
await createKey(currentUser.userId); | ||
} | ||
``` | ||
|
||
See [OAuth account linking](/guidebook/oauth-account-linking) guide for details. | ||
|
||
## Extension | ||
|
||
If you're using one of the built in providers, `OAuth2ProviderAuth.validateCallback()` and `OAuth2ProviderAuthWithPKCE.validateCallback()` will return a provider-extended instance of `ProviderUserAuth`. This means in addition to the methods of `ProviderUserAuth`, it includes a few other properties and methods. While this isn't strictly standardized, all providers include the provider user (e.g. github user) and an access token (refresh token if available). | ||
|
||
### Get provider user | ||
|
||
```ts | ||
const githubUserAuth = await githubAuth.validateCallback(code); | ||
const githubUsername = githubUserAuth.githubUser.login; | ||
``` | ||
|
||
### Get API tokens | ||
|
||
```ts | ||
const githubUserAuth = await githubAuth.validateCallback(code); | ||
const githubAccessToken = githubUserAuth.githubTokens.accessToken; | ||
``` |
Oops, something went wrong.