-
Notifications
You must be signed in to change notification settings - Fork 248
Feat: New auth docs #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat: New auth docs #566
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
112d1f2
Updte auth docs
Meldiron 7e674d6
Leftover, hihi
Meldiron b548457
Remove external auth page
Meldiron 3303670
Finish auth G2 docs
Meldiron fb2524e
Apply suggestions from code review
Meldiron efaea26
review changes
Meldiron 905180b
Merge branch 'feat-new-auth-docs' of https://github.com/appwrite/webs…
Meldiron 7fd9fc9
Remove double dots
Meldiron 7a9e156
Copy changes to duplicate section
Meldiron bdad0cb
Apply suggestions from code review
c618c9f
Merge branch '1.5.x' into feat-new-auth-docs
bdd6377
Fix tables magic url vs OTP
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
9E7A
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,53 @@ | ||
--- | ||
layout: article | ||
title: Custom token login | ||
description: Limitless authentication flow in Appwrite. Find out how to implement custom authentication flow or connect to 3rd party authentication providers. | ||
--- | ||
|
||
Tokens are short-lived secrets created by an [Appwrite Server SDK](/docs/sdks#server) that can be exchanged for session by a [Client SDK](/docs/sdks#client) to log in users. You may already be familiar with tokens if you checked out [Magic URL login](/docs/products/auth/magic-url), [Email OTP login](/docs/products/auth/email-otp) or [Phone (SMS) login](/docs/products/auth/phone-sms). | ||
|
||
Custom token allows you to use [Server SDK](/docs/sdks#server) to generate tokens for your own implementations. This allows you to code your own authentication methods using Appwrite Functions or your own backend. You could implement username and password sign-in, captcha-protected authentication, phone call auth, and much more. Custom tokens also allow you to skip authentication which is useful when you integrate Appwrite with external authenticaion providers such as Auth0, TypingDNA, or any provider trusted by your users. | ||
|
||
# Create custom token {% #create-custom-token %} | ||
|
||
Once you have your server endpoint prepared either in an Appwrite Function or a server integration, you can use the [Create token](/docs/references/cloud/server-node/users#createToken) endpoint of the [Users API](/docs/products/auth/users) to generate a token. | ||
|
||
```js | ||
import { Client, Users } from "node-appwrite"; | ||
|
||
const client = new Client() | ||
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint | ||
.setProject('<PROJECT_ID>'); // Your project ID | ||
.setKey('<API_KEY>'); // Your secret API key | ||
|
||
const users = new Users(client); | ||
|
||
const token = await users.createToken('[USER_ID]'); | ||
|
||
console.log(token.secret); | ||
``` | ||
|
||
The newly created token includes a secret which is 6 character long hexadecimal string. You can configure length of the secret and expiry when creating a token. | ||
|
||
If you are integrating with external authentication providers or implementing your own authentication, make sure to validate user authenticated properly before generating a token for them. | ||
|
||
If you are implementing token-based authentication flow, share the token secret with user over any channel of your choice instead of directly giving it to him in the response. | ||
Meldiron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
If the client doesn't know the user's ID during authentication, we recommend to directly return user ID to the client as part of this step. If necessary, you can check if the user with an user ID exists first, and create a new user if needed. | ||
|
||
# Login {% #login %} | ||
|
||
Once the client receives a token secret, we can use it to authenticate the user in the application. Use the [Client SDK's](/docs/sdks#client) [Create session endpoint](/docs/references/cloud/client-web/account#createSession) to exchange the token secret for a valid session, which logs the user. | ||
```js | ||
import { Client, Account } from "appwrite"; | ||
|
||
const client = new Client() | ||
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint | ||
.setProject('<PROJECT_ID>'); // Your project ID | ||
|
||
const account = new Account(client); | ||
|
||
await account.createSession('[USER_ID]', '[SECRET]'); 46CA td> | ||
``` | ||
|
||
When the session is successfully created, the session is stored in a persistent manner and you can now do requests as authorized user from the application. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need more languages?