Main interface to the Identity API (v1). Use button() to create the Identity button and on() to subscribe to events.
button()
on()
identity-ts-init mode=stack label="SDK Initialization"
"Initialize the Klarna SDK with clientId and locale."
const klarna = await window.Klarna.init({ clientId: "klarna_live_client_elZGI1B5dHBIRWcjZrNldnbEVj...", locale: 'sv-SE'}); Copy
const klarna = await window.Klarna.init({ clientId: "klarna_live_client_elZGI1B5dHBIRWcjZrNldnbEVj...", locale: 'sv-SE'});
identity-js mode=tabs label="JavaScript"
"Create the Identity button, mount it, subscribe to ready/click/signin/error events, and unmount on cleanup."
"1.1 Render the Identity Button"
const siwkButton = klarna.Identity.button({ scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton.mount('#container'); Copy
const siwkButton = klarna.Identity.button({ scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton.mount('#container');
"1.2 Capture events"
siwkButton.on("ready", async () => { // implement logic});siwkButton.on("click", async () => { // implement logic});klarna.Identity.on("signin", async (signinResponse) => { // implement logic});klarna.Identity.on("error", async (error) => { // implement error handling logic}); Copy
siwkButton.on("ready", async () => { // implement logic});siwkButton.on("click", async () => { // implement logic});klarna.Identity.on("signin", async (signinResponse) => { // implement logic});klarna.Identity.on("error", async (error) => { // implement error handling logic});
"1.3 Cleanup"
siwkButton.unmount(); Copy
siwkButton.unmount();
identity-html-2 mode=stack label="HTML (custom button)"
"Use your own button in the DOM and attach Identity behavior with attach()."
<button id="merchants-custom-button">I am a custom button</button> Copy
<button id="merchants-custom-button">I am a custom button</button>
"2.2 Attach Identity Button behavior"
const siwkButton = klarna.Identity.button({ scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton.attach('#merchants-custom-button'); Copy
const siwkButton = klarna.Identity.button({ scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton.attach('#merchants-custom-button');
"2.3 Capture events"
"2.4 Cleanup"
siwkButton.detach(); Copy
siwkButton.detach();
"3. Multiple Identity Buttons"
const siwkButton = klarna.Identity.button({ scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton.mount("#container-1")// SECOND BUTTON RENDERED IN THE SAME PAGEconst siwkButton2 = klarna.Identity.button({ // Notice, for multiple buttons we need to provide an ID id: 'secondIdentityButton', scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton2.mount("#container-2")// CleanupsiwkButton.unmount()siwkButton2.unmount() Copy
const siwkButton = klarna.Identity.button({ scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton.mount("#container-1")// SECOND BUTTON RENDERED IN THE SAME PAGEconst siwkButton2 = klarna.Identity.button({ // Notice, for multiple buttons we need to provide an ID id: 'secondIdentityButton', scope: "openid offline_access profile:name", redirectUri: "http://localhost:3000/callback",})siwkButton2.mount("#container-2")// CleanupsiwkButton.unmount()siwkButton2.unmount()
Optional
Identity
Identity.button
general-availability
true
acquiring_partner Returns the button with given id
If id is not provided, returns the first button instance
If no button instance found returns undefined
acquiring_partner Creates the button with given configuration
id attribute is required for creating more than one Identity Button.
id
Identity.onSignIn
acquiring_partner Registers signin event handler.
signin
This event handler needs to be registered also on the redirect callback page to trigger handling redirect response.
Identity.onError
acquiring_partner Registers error event handler.
error
Main interface to the Identity API (v1). Use
button()to create the Identity button andon()to subscribe to events.Example Group
identity-ts-init mode=stack label="SDK Initialization"
Description
"Initialize the Klarna SDK with clientId and locale."
Example Group
identity-js mode=tabs label="JavaScript"
Description
"Create the Identity button, mount it, subscribe to ready/click/signin/error events, and unmount on cleanup."
Example Tab Label
"1.1 Render the Identity Button"
Example Tab Label
"1.2 Capture events"
Example Tab Label
"1.3 Cleanup"
Example Group
identity-html-2 mode=stack label="HTML (custom button)"
Description
"Use your own button in the DOM and attach Identity behavior with attach()."
Example Group
identity-js mode=tabs label="JavaScript"
Example Tab Label
"2.2 Attach Identity Button behavior"
Example Tab Label
"2.3 Capture events"
Example Tab Label
"2.4 Cleanup"
Example Tab Label
"3. Multiple Identity Buttons"