Optionalid: string"Returns an existing Identity button instance by its ID.
If no ID is provided, returns the first button instance.
If no button instance is found, returns undefined.
Use this to retrieve a previously created button for cleanup or re-mounting."
Data required to create an Identity button.
OptionalclientType?: "public" | "confidential""Creates an Identity button with the given configuration. The redirectUri
must point to the page where the customer lands after authenticating with
Klarna — you must also register the signin handler on that page. The
scope defines which profile data you request (e.g. 'profile:name profile:email').
The id attribute is required when creating more than one Identity button
on the same page.
After creating the button, call mount() to render it into a DOM container."
Promise that resolves when the login state is successfully cleared
"Clears the customer's login state and removes personalized experience.
This method should be called by partners once a customer signs out from their application. It clears the authenticated session and removes any personalized Klarna experience from the Web SDK. This ensures that no customer-specific data or session persists after sign-out."
"Registers a signin event handler. This fires when the customer successfully
authenticates with Klarna and the requested profile data is available.
Important: This handler must also be registered on the redirect callback
page (the redirectUri you provided when creating the button) so that the
redirect response is properly handled."
klarna.Identity.on("signin", async (response) => {
const { customerProfile } = response;
// Use the profile data to pre-fill forms or create an account
console.log("Signed in:", customerProfile.givenName, customerProfile.familyName);
console.log("Email:", customerProfile.email);
// Send the profile to your backend
await fetch("/api/auth/klarna", {
method: "POST",
body: JSON.stringify(customerProfile),
});
});
"Registers an error event handler for the Identity flow. This fires when
any error occurs during sign-in (e.g. network failure, user denied consent,
or invalid configuration). Register this handler to provide graceful error
handling instead of letting errors propagate unhandled."
Main interface to the Identity API. Use
button()to create the Identity button andon()to subscribe to events. See Identity API for full documentation.Example 1: Generate button with SDK
This is the recommended and preferred method of integration
Example Group
label="JavaScript"
Description
"Create the Identity button, mount it to a container, subscribe to render/click/signin/error events, and unmount on cleanup."
Example: 1.1 Render the Identity Button
Example: 1.2 Capture events
Example: 1.3 Cleanup
Example 2: Attach Identity Button behavior to a custom button
Example Group
label="HTML (custom button)"
Description
"Use your own button in the DOM and attach Identity behavior with attach(). Register events and detach when done."
Example Group
label="JavaScript"
Example: 2.2 Attach Identity Button behavior
Example: 2.3 Capture events
Example: 2.4 Cleanup
Example: 3. Multiple Identity Buttons
Example Group
label="CSS"
Description
"Optional: customize button dimensions (min width 48px, height 35–60px)."
Package Interface
Klarna-lifecycle-stage
gated