import { createDirectus, authentication } from '@directus/sdk';const client = createDirectus('https://your-project.directus.app') .with(authentication('json'));// Login with credentialsawait client.login('user@example.com', 'password');// Access token is now stored and used automaticallyconst user = await client.request(readMe());
Passwords are hashed using Argon2, a secure password hashing algorithm:
import argon2 from 'argon2';// During user creation/password changeconst hashedPassword = await argon2.hash(plainTextPassword);// During authenticationconst isValid = await argon2.verify(user.password, providedPassword);
AUTH_PROVIDERS="google"# OAuth ConfigurationAUTH_GOOGLE_DRIVER="oauth2"AUTH_GOOGLE_CLIENT_ID="your-client-id"AUTH_GOOGLE_CLIENT_SECRET="your-client-secret"AUTH_GOOGLE_AUTHORIZE_URL="https://accounts.google.com/o/oauth2/v2/auth"AUTH_GOOGLE_ACCESS_URL="https://oauth2.googleapis.com/token"AUTH_GOOGLE_PROFILE_URL="https://www.googleapis.com/oauth2/v2/userinfo"# Optional: Auto-create usersAUTH_GOOGLE_ALLOW_PUBLIC_REGISTRATION="true"AUTH_GOOGLE_DEFAULT_ROLE_ID="role-uuid"# Optional: Sync user info on loginAUTH_GOOGLE_SYNC_USER_INFO="true"# Optional: Role mapping based on groupsAUTH_GOOGLE_ROLE_MAPPING='json:{"admin-group":"admin-role-uuid"}'
// Redirect user to OAuth providerwindow.location.href = 'https://your-project.directus.app/auth/login/google';// After callback, user is authenticated// Tokens are available via cookie or redirected with token
AUTH_PROVIDERS="ldap"AUTH_LDAP_DRIVER="ldap"AUTH_LDAP_CLIENT_URL="ldap://ldap.example.com:389"AUTH_LDAP_BIND_DN="cn=admin,dc=example,dc=com"AUTH_LDAP_BIND_PASSWORD="admin-password"AUTH_LDAP_USER_DN="ou=users,dc=example,dc=com"AUTH_LDAP_USER_ATTRIBUTE="cn"AUTH_LDAP_USER_SCOPE="one"# Optional: Group mappingAUTH_LDAP_GROUP_DN="ou=groups,dc=example,dc=com"AUTH_LDAP_GROUP_ATTRIBUTE="member"AUTH_LDAP_GROUP_SCOPE="one"# Optional: Attribute mappingAUTH_LDAP_MAIL_ATTRIBUTE="mail"AUTH_LDAP_FIRST_NAME_ATTRIBUTE="givenName"AUTH_LDAP_LAST_NAME_ATTRIBUTE="sn"# Default role for LDAP usersAUTH_LDAP_DEFAULT_ROLE_ID="role-uuid"