Authentication utilities including password hashing and OAuth support.
Provides patterns for:
Authentication utilities including password hashing and OAuth support. Provides patterns for: - Password-based authentication with bcrypt - OAuth flows (GitHub, extensible to other providers)
(authenticate-user db-or-system email password)Authenticates a user by email and password.
Returns the user entity if authentication succeeds, nil otherwise.
Example: (authenticate-user ctx "user@example.com" "password123")
Authenticates a user by email and password. Returns the user entity if authentication succeeds, nil otherwise. Example: (authenticate-user ctx "user@example.com" "password123")
(create-user-tx {:keys [password] :as user-data})Creates a transaction map for a new user with password.
Required: :user/email - User's email address :password - Non-blank plain text password (will be hashed)
Optional: :user/username - Username :user/id - UUID (generated if not provided) Any other user attributes
Returns a transaction map ready for submit-tx.
Note: The :user/id attribute must be unique in the schema for lookups to work.
Creates a transaction map for a new user with password. Required: :user/email - User's email address :password - Non-blank plain text password (will be hashed) Optional: :user/username - Username :user/id - UUID (generated if not provided) Any other user attributes Returns a transaction map ready for submit-tx. Note: The :user/id attribute must be unique in the schema for lookups to work.
(create-verification-token user-ref
&
{:keys [expires-in-hours] :or {expires-in-hours 24}})Creates a verification token for email confirmation.
The user-ref can be a UUID (converted to lookup ref) or a lookup ref. Note: The user must exist before creating a verification token.
Returns a map with :token and transaction data.
Creates a verification token for email confirmation. The user-ref can be a UUID (converted to lookup ref) or a lookup ref. Note: The user must exist before creating a verification token. Returns a map with :token and transaction data.
(delete-verification-token-tx db-or-conn-or-system token)Creates a transaction to delete a verification token.
For Datalevin, this returns a retraction using the entity ID. The token must exist for this to work.
Creates a transaction to delete a verification token. For Datalevin, this returns a retraction using the entity ID. The token must exist for this to work.
(find-user-by-email db-or-system email)Finds a user by email address.
Returns the user entity without password hash, or nil if not found.
Finds a user by email address. Returns the user entity without password hash, or nil if not found.
(find-user-by-github-id db-or-system github-id)Finds a user by their GitHub ID.
Returns the user entity or nil if not found.
Finds a user by their GitHub ID. Returns the user entity or nil if not found.
(find-user-by-id db-or-system user-id)Finds a user by their UUID.
Returns the user entity without password hash, or nil if not found.
Finds a user by their UUID. Returns the user entity without password hash, or nil if not found.
(github-authorize-url {:keys [client-id redirect-uri scope state]
:or {scope "user:email"}})Generates the GitHub OAuth authorization URL.
Options: :client-id - GitHub OAuth app client ID (required) :redirect-uri - Callback URL (required) :scope - OAuth scopes (default "user:email") :state - CSRF state parameter (recommended)
Generates the GitHub OAuth authorization URL. Options: :client-id - GitHub OAuth app client ID (required) :redirect-uri - Callback URL (required) :scope - OAuth scopes (default "user:email") :state - CSRF state parameter (recommended)
(github-create-user-tx github-user)Creates transaction data for creating a user from GitHub profile.
Takes GitHub user data and returns a transaction map. Uses :user/github-id as the unique identifier for the new user.
Example: (let [gh-user (github-get-user access-token)] (when-not (find-user-by-github-id conn (:id gh-user)) (submit-tx conn [(github-create-user-tx gh-user)])))
Creates transaction data for creating a user from GitHub profile.
Takes GitHub user data and returns a transaction map.
Uses :user/github-id as the unique identifier for the new user.
Example:
(let [gh-user (github-get-user access-token)]
(when-not (find-user-by-github-id conn (:id gh-user))
(submit-tx conn [(github-create-user-tx gh-user)])))(github-exchange-code {:keys [client-id client-secret code redirect-uri]})Exchanges an OAuth authorization code for an access token.
Returns a map with :access_token or throws on error.
Exchanges an OAuth authorization code for an access token. Returns a map with :access_token or throws on error.
(github-find-or-create-user-tx github-user)Deprecated alias for github-create-user-tx.
This function never performed a lookup; use find-user-by-github-id first if you need true find-or-create behavior.
Deprecated alias for github-create-user-tx. This function never performed a lookup; use find-user-by-github-id first if you need true find-or-create behavior.
(github-get-user access-token)Fetches the authenticated user's profile from GitHub.
Returns a map with GitHub user data including :id, :login, :email, :avatar_url, etc.
Fetches the authenticated user's profile from GitHub. Returns a map with GitHub user data including :id, :login, :email, :avatar_url, etc.
(hash-password password)(hash-password password {:keys [iterations] :or {iterations 12}})Hashes a password using bcrypt.
Options: :iterations - bcrypt work factor (default 12)
Hashes a password using bcrypt. Options: :iterations - bcrypt work factor (default 12)
(oauth-authorize-url {:keys [authorize-url client-id redirect-uri scope state
extra-params]})Generates an OAuth authorization URL for any provider.
Options: :authorize-url - Provider's authorization endpoint (required) :client-id - OAuth app client ID (required) :redirect-uri - Callback URL (required) :scope - OAuth scopes (optional) :state - CSRF state parameter (recommended) :extra-params - Map of additional query params
Generates an OAuth authorization URL for any provider. Options: :authorize-url - Provider's authorization endpoint (required) :client-id - OAuth app client ID (required) :redirect-uri - Callback URL (required) :scope - OAuth scopes (optional) :state - CSRF state parameter (recommended) :extra-params - Map of additional query params
(oauth-exchange-code {:keys [token-url client-id client-secret code redirect-uri
extra-params]})Exchanges an OAuth code for tokens with any provider.
Options: :token-url - Provider's token endpoint (required) :client-id - OAuth app client ID (required) :client-secret - OAuth app client secret (required) :code - Authorization code (required) :redirect-uri - Callback URL (required) :extra-params - Map of additional form params
Returns the parsed JSON response body.
Exchanges an OAuth code for tokens with any provider. Options: :token-url - Provider's token endpoint (required) :client-id - OAuth app client ID (required) :client-secret - OAuth app client secret (required) :code - Authorization code (required) :redirect-uri - Callback URL (required) :extra-params - Map of additional form params Returns the parsed JSON response body.
(verify-password password hash)Verifies a password against a hash.
Returns true if the password matches, false otherwise.
Verifies a password against a hash. Returns true if the password matches, false otherwise.
(verify-token db-or-conn-or-system token)Verifies an email verification token.
Returns the user ID if valid and not expired, nil otherwise.
Verifies an email verification token. Returns the user ID if valid and not expired, nil otherwise.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |