Arctic v1

Salesforce

Implements OpenID Connect.

For usage, see OAuth 2.0 provider with PKCE.

import { Salesforce } from "arctic";

const salesforce = new Salesforce(clientId, clientSecret, redirectURI);
const url: URL = await salesforce.createAuthorizationURL(state, {
	// optional
	scopes
});
const tokens: SalesforceTokens = await salesforce.validateAuthorizationCode(code);
const tokens: SalesforceTokens = await salesforce.refreshAccessToken(refreshToken);

Get user profile

Add the profile scope. Optionally add the email scope to get user email.

const url = await salesforce.createAuthorizationURL(state, {
	scopes: ["profile", "email"]
});

Use the /userinfo endpoint.

const tokens = await salesforce.validateAuthorizationCode(code);
const response = await fetch("https://login.salesforce.com/services/oauth2/userinfo", {
	headers: {
		Authorization: `Bearer ${tokens.accessToken}`
	}
});
const user = await response.json();