xumm-oauth2-pkce
TypeScript icon, indicating that this package has built-in type declarations

2.8.7 • Public • Published

Xumm OAuth2 Authorization Code PKCE flow

Part of the "Xumm Universal SDK", which is the preferred way of interacting with the Xumm ecosystem from JS/TS environments: https://www.npmjs.com/package/xumm - https://github.com/XRPL-Labs/Xumm-Universal-SDK

Xumm JS SDK for client side only OAuth2 PKCE (Authorization Code flow) auth npm version

Questions? https://xumm.readme.io/discuss

Demo? https://oauth2-pkce-demo.xumm.dev

NPM: https://www.npmjs.com/package/xumm-oauth2-pkce

Constructor

new XummPkce('api-key-uuidv4', { options })

Options

interface XummPkceOptions {
  redirectUrl: string;      // Defaults to `document.location.href`, e.g. to add state params.
  rememberJwt: boolean;     // Defaults to `true`
  storage: Storage;         // Defaults to window.localStorage
  implicit: boolean;        // Defaults to `false`, `true` allows x-browser sign in, but it less secure
}

Samples:

Event based

Please note: please use the Event based sample (above) if possible: this is more compatible with future releases than the promise-based (await/async) method as displayed below.

Events (emitted)

  • success = User signed in successfully, sdk.state() returns .me and .sdk objects
  • retrieved = Retrieved existing session after e.g. browser refresh or mobile redirect, sdk.state() returns .me and .sdk objects
  • error = Error, expected (e.g. user cancelled) or unexpected (...), returns argument error with an Error() object, sdk.state() returns null

Promise based sample

const xumm = new XummPkce("uuid-uuid-uuid-uuid");

const xummSignInHandler = (state) => {
  if (state.me) {
    const { sdk, me } = state;
    console.log("state", me);
    // Also: sdk » xumm-sdk (npm)
  }
};
// To pick up on mobile client redirects:
xumm.on("retrieved", async () => {
  console.log("Retrieved: from localStorage or mobile browser redirect");
  xummSignInHandler(await xumm.state());
});

// E.g. when clicking a button:
document.getElementById("somebutton").onclick = () => {
  xumm.authorize().then((session) => {
    xummSignInHandler(session);
  });
};

CDN (browser):

A browserified version (latest) is available at JSDelivr & direclty from the xumm.app domain:

<script src="https://xumm.app/assets/cdn/xumm-oauth2-pkce.min.js"></script>

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.8.71,207latest

Version History

VersionDownloads (Last 7 Days)Published
2.8.71,207
2.8.5124
2.8.41
2.8.31
2.8.213
2.8.10
2.8.00
2.7.90
2.7.80
2.7.70
2.7.60
2.7.50
2.7.40
2.7.30
2.7.20
2.7.10
2.7.00
2.6.00
2.5.50
2.5.40
2.5.30
2.5.20
2.5.10
2.5.00
2.4.00
2.3.00
2.2.00
2.1.60
2.1.50
2.1.10
2.1.00
2.0.70
2.0.60
2.0.50
2.0.30
2.0.20
2.0.10
2.0.00
1.0.00

Package Sidebar

Install

npm i xumm-oauth2-pkce

Weekly Downloads

1,346

Version

2.8.7

License

MIT

Unpacked Size

350 kB

Total Files

7

Last publish

Collaborators

  • kevinkoobs
  • koen_xrpl-labs
  • wietsewind