npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xal-node-fork

v2.0.3

Published

XAL implementation in Typescript. Used for authenticating to services like Xbox.

Downloads

33

Readme

PUll from remote (main) project via

git pull public main

xal-node

xal-node: Typescript implementation for Xbox Authentication Library (XAL)

Installing xal-node

You can install the project with npm. In the project directory, run:

$ npm install xal-node

Building xal-node

Once the repository has been cloned you can run the command below to build the project:

$ npm run build

CLI

You can install the xbox-auth cli app using the instructions below:

$ npm install -g xal-node

Once installed make sure the npm path is properly set. You should be able to run xbox-auth to start the program.

Available commands

| Command | Description | |---------|-------------| | xbox-auth auth | Runs the authentication flow and provides an URL to login to. | | xbox-auth show | Shows the current status of the tokens and if they are expired or not. | | xbox-auth refresh | Refreshes the current stored tokens to new up to date tokens without running the full flow again. | | xbox-auth tokens | Fetches all tokens for use with xCloud and xHome | | xbox-auth logout | Removes the current stored tokens |

Tokens

The tokens are stored in the current working directory in the file .xbox.tokens.json. In this file you will have 3 directories: userToken, sisuToken and jwtKeys. The userToken and jwtKeys are important. Those are unique and allows us to refresh the tokens once they are expired. The sisuToken can always be renewed using the userToken and jwtKeys but we store them because it makes retrieving other tokens easier.

API examples

Check out src/bin/auth.ts for a good example. This file provides a quite easy to read example on how to authenticate, retrieve tokens and check the status.

Load the XAL library and Tokenstore:

this._tokenStore = new TokenStore()
this._tokenStore.load('.xbox.tokens.json') // File will be saved in the current working directory

this._xal = new Xal(this._tokenStore)

To authenticate:

this._xal.getRedirectUri().then((redirect) => {
    console.log('redirect', redirect)

    // Perform authentication in a web browser and catch the redirect uri. You can pass the redirect uri directly into the function.

    this._xal.authenticateUser(this._tokenStore, redirect, redirectUri).then((result) => {
        console.log('Authentication result:', result)
    })

    // Alternatively if you want to extract the code and state yourself, you can do that too and pass the code and state.
    const code = '<extracted code from uri>'
    const state = '<extracted state from uri>'

    this._xal.authenticateUserUsingCode(this._tokenStore, redirect, code, state).then((result) => {
        console.log('Authentication result:', result)
    })
}).catch((err) => {
    console.error(err)
})

To refresh the user token without user interaction:

this._xal.refreshTokens(this._tokenStore).then((tokens) => {
    console.log('tokens', tokens)
}).catch((err) => {
    if(err instanceof TokenRefreshError) {
        console.log('Failed to refresh tokens. Please authenticate again. Error details:', err)
    } else {
        console.error('refreshTokens Error:', err)
    }
})

Retrieve MSAL token:

this._xal.getMsalToken(this._tokenStore).then((msalToken) => {
    console.log('msalToken', msalToken)
}).catch((err) => {
    console.error(err)
})

Retrieve web token for interaction with the web api's:

this._xal.getWebToken(this._tokenStore).then((webToken) => {
    console.log('webToken', webToken)
}).catch((err) => {
    console.error(err)
})

Retrieve the xCloud and xHome streaming tokens:

this._xal.getStreamingToken(this._tokenStore).then((streamingTokens) => {
    console.log('streamingTokens', streamingTokens)
}).catch((err) => {
    console.error(err)
})

Other AppId and titleId's

It is possible to authenticate to different services using this library as well. Not all calls are supported but the authentication part is quite general. You can override the titleId like below:

const xal = xallib.Xal()
xal._app = {
    AppId: '<appId>',
    TitleId: '<titleId>',
    RedirectUri: '<redirectUri>',
}

Credits

Big thanks to @tuxuser and Team OpenXbox for creating the xal-rs library and giving the inspiration to port this over to Typescript