Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@clerk/backend
Advanced tools
Clerk Backend SDK - REST Client for Backend API & JWT verification utilities
@clerk/backend is a Node.js package that provides backend functionality for authentication and user management. It allows developers to integrate user authentication, manage user sessions, and handle user data securely and efficiently.
User Authentication
This feature allows you to authenticate users using a token. The code sample demonstrates how to verify a user's token and retrieve user information.
const { Clerk } = require('@clerk/backend');
const clerk = new Clerk({ apiKey: 'your-api-key' });
async function authenticateUser(token) {
const user = await clerk.users.verifyToken(token);
return user;
}
authenticateUser('user-token').then(user => console.log(user)).catch(err => console.error(err));
Session Management
This feature allows you to manage user sessions. The code sample demonstrates how to retrieve a session by its ID.
const { Clerk } = require('@clerk/backend');
const clerk = new Clerk({ apiKey: 'your-api-key' });
async function getSession(sessionId) {
const session = await clerk.sessions.getSession(sessionId);
return session;
}
getSession('session-id').then(session => console.log(session)).catch(err => console.error(err));
User Management
This feature allows you to manage user data. The code sample demonstrates how to retrieve user information by user ID.
const { Clerk } = require('@clerk/backend');
const clerk = new Clerk({ apiKey: 'your-api-key' });
async function getUser(userId) {
const user = await clerk.users.getUser(userId);
return user;
}
getUser('user-id').then(user => console.log(user)).catch(err => console.error(err));
Auth0 is a flexible, drop-in solution to add authentication and authorization services to your applications. It provides a wide range of features including social login, multi-factor authentication, and user management. Compared to @clerk/backend, Auth0 offers more extensive integrations and a broader set of features but can be more complex to set up.
Firebase Admin SDK allows you to integrate Firebase services into your server-side applications. It provides functionalities for user authentication, database management, and cloud messaging. Compared to @clerk/backend, Firebase Admin SDK offers a more comprehensive suite of backend services but may require more configuration and setup.
Passport is an authentication middleware for Node.js that supports a wide range of authentication strategies. It is highly modular and can be integrated with various authentication providers. Compared to @clerk/backend, Passport is more flexible and customizable but requires more effort to implement and manage different authentication strategies.
This package provides Clerk Backend API resources and low-level authentication utilities for JavaScript environments. It is mostly used as the base for other Clerk SDKs but it can be also used on its own.
{data, errors}
instead of throwing errors.Works on Node >= 16 or on any V8 Isolates runtimes such as Cloudflare Workers.
npm install @clerk/backend
import { Clerk } from '@clerk/backend';
const clerk = Clerk({ apiKey: '...' });
await clerk.users.getUser("user_...");
Create Clerk SDK that includes an HTTP Rest client for the Backend API and session verification helpers. The clerk object contains the following APIs and methods:
import { Clerk } from '@clerk/backend';
const clerk = Clerk({ apiKey: '...' });
await clerk.users.getUser('user_...');
// Available APIs
clerk.allowlistIdentifiers;
clerk.clients;
clerk.emailAddresses;
clerk.emails;
clerk.interstitial;
clerk.invitations;
clerk.organizations;
clerk.phoneNumbers;
clerk.redirectUrls;
clerk.sessions;
clerk.signInTokens;
clerk.smsMessages;
clerk.users;
// These functions should be used by framework-specific libraries, such as @clerk/nextjs or @clerk/remix.
// Compute the authentication state given the request parameters.
clerk.authenticateRequest(options);
// Build debug payload of the request state.
clerk.debugRequestState(requestState);
// Load clerk interstitial from this package
clerk.localInterstitial(options);
// Load clerk interstitial from the public Backend API endpoint
clerk.remotePublicInterstitial(options);
// Load clerk interstitial from the public Private API endpoint (Deprecated)
clerk.remotePrivateInterstitial(options);
Verifies a Clerk generated JWT (i.e. Clerk Session JWT and Clerk JWT templates). The key resolution via JWKS or local values is handled automatically.
import { verifyToken } from '@clerk/backend';
verifyToken(token, {
issuer: '...',
authorizedParties: '...',
});
Verifies a Clerk generated JWT (i.e. Clerk Session JWT and Clerk JWT templates). The key needs to be provided in the options.
import { verifyJwt } from '@clerk/backend';
verifyJwt(token, {
key: JsonWebKey,
issuer: '...',
authorizedParties: '...',
});
Decodes a JWT.
import { decodeJwt } from '@clerk/backend';
decodeJwt(token);
Verifies that the JWT has a valid signature. The key needs to be provided.
import { hasValidSignature } from '@clerk/backend';
hasValidSignature(token, jwk);
Generates a debug payload for the request state
import { debugRequestState } from '@clerk/backend';
debugRequestState(requestState);
Generates a debug payload for the request state. The debug payload is available via window.__clerk_debug
.
import { loadInterstitialFromLocal } from '@clerk/backend';
loadInterstitialFromLocal({
frontendApi: '...',
pkgVersion: '...',
debugData: {},
});
Builds the AuthObject when the user is signed in.
import { signedInAuthObject } from '@clerk/backend';
signedInAuthObject(jwtPayload, options);
Builds the empty AuthObject when the user is signed out.
import { signedOutAuthObject } from '@clerk/backend';
signedOutAuthObject();
Removes sensitive private metadata from user and organization resources in the AuthObject
import { sanitizeAuthObject } from '@clerk/backend';
sanitizeAuthObject(authObject);
Removes any private_metadata
and privateMetadata
attributes from the object to avoid leaking sensitive information to the browser during SSR.
import { prunePrivateMetadata } from '@clerk/backend';
prunePrivateMetadata(obj);
You can get in touch with us in any of the following ways:
We're open to all community contributions! If you'd like to contribute in any way, please read our contribution guidelines.
@clerk/backend
follows good practices of security, but 100% security cannot be assured.
@clerk/backend
is provided "as is" without any warranty. Use at your own risk.
For more information and to report security issues, please refer to our security documentation.
This project is licensed under the MIT license.
See LICENSE for more information.
FAQs
Clerk Backend SDK - REST Client for Backend API & JWT verification utilities
The npm package @clerk/backend receives a total of 222,510 weekly downloads. As such, @clerk/backend popularity was classified as popular.
We found that @clerk/backend demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.