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

node-mcauth

v0.1.0-beta

Published

new mineraft authentication protocol https://login.live.com/oauth20_authorize.srf?client_id=bc071bd2-cad2-44d6-8718-cb0841885bb9&response_type=code&redirect_uri=https://mc-auth.cc2.workers.dev&scope=XboxLive.signin%20offline_access&state=

Downloads

6

Readme

node-mcAuth

Node JS Implementation for handling OAuth2 with the new upcoming minecraft authentication scheme.

Quickstart :

First, to initiate a Client that will contain all the methods you need, do :

const AuthClient = new Client(clientID, clientSecret, redirectURI, options)

Client ID and Client Secret should be from your azure application page (See me), redirectURI should be provided if you want to use genURL()

Generate a URL for OAuth2 :

const AuthClient = require('node-mcAuth').Client;
AuthClient.genURL();
// returns an object with URL and state

This will generate a valid one-time URL for authentication

Listen to requests

// Keep in mind that your redirectURI must end with '/callback', or otherwise you need to provide the path yourself as the 2nd argument. You can also pass an express app to the function.
//NOTE : this is not mandatory, only helps you handle the incoming requests easier.
AuthClient.init().listen(80); // This will listen to all traffic coming from port 80.

//Upon request : 
AuthClient.on('incomingAuth',(request,response,stateValidity))
// Request and Response are unmodified express objects
// stateValidity is whether an activeState has been found

Authenticating :

const code = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';// assuming code is the code you got from the callback URL : 
AuthClient.authenticateCode(code)
    .then(connectXbox)
    .then(XboxXSTS) // you can chain them like this
    .then(r=>{
        //do something with the response in JSON idk
        return r
    })
    .then(mcLoginWithXbox)
    .then(checkMcOwnership)
    .then(getUUIDfromToken)
    .then(response=>{
        // Ayy Finally you got the user's UUID
    })
// Of course, you are not forced to do every single step if you only want to check they own minecraft or something.

Options

We support a lot of options for customization. Some options are global only, others are local and global. Local always overrides global.

Global-Only : (Note : the values provided are the default values)

{
    backendOnly:false; // If true, disables state-managing and genURL. redirectURI isn't needed in this case
}

Local and Global :

{
    offline:false, // If true, additionally prompts user for an offline token. This can be used to refresh a token ( TODO ) and get their profile again without having to ask them to authenticate blablabla.
    state:false, // If true, a state is generated. This is very useful for 1. knowing which user it is and 2. checking if there is some XSRF or some other voodoo magic that is abusing your OAuth.
    stateOptions:{
        stateLength: 16, // Length of state, can't be larger than 128
        ttl: 60, // Time in seconds for the state to be valid. Can't be more than 1 hour.
        allowedChars: '1234567890abcdef-' // Potential characters to be inside the state. Recommendation : don't put emojis.
    }
}

Error Handling :

One moment or another, there will be an error. What caused it? No one can tell for sure. Instead of throwing another piece of coin down the wishing well to hope for another day without any errors, try catching them ! Let's use the snippet from above.

const code = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';// assuming code is the code you got from the callback URL : 
authenticateCode(code)
    .then(connectXbox)
    .then(XboxXSTS) // you can chain them like this
    .then(r=>{
        //do something with the response in JSON idk
        return r
    })
    .then(mcLoginWithXbox)
    .then(checkMcOwnership)
    .then(getUUIDfromToken)
    .then(response=>{
        // Ayy Finally you got the user's UUID
    })
    .catch(console.log); // Here, you are simply console.logging the error.

Custom errors :

The errors are written in english, so if you are using this for, say, a target audience of Spanish people, you might want to provide Spanish translations. As of Jan 27, 2021, you can't PR translations for error messages yet, BUT you can do :

const Errors = require('node-mcAuth').Errors;
// ...
//blabla a lot of thens later
.catch(err=>{
    if(err === Errors.HTTPError401) console.log('Ayo you are not authorized');
    else console.log(err); // Otherwise, still log it. Remember, as best practice, never silence errors. It will be a pain for troubleshooting
});