Skip to content

Display an electronJs window to authenticate Minecraft accounts through Xbox Live.

License

Notifications You must be signed in to change notification settings

makis-san/electron-mc-auth

Repository files navigation

electron-mc-auth

Display an electronJs window to authenticate Minecraft accounts through Xbox Live.

Getting started | MCLC | Contribuittions

Getting started

Start by installing the package with your preffered package manager for node.

yarn add electron-mc-auth

or

npm install electron-mc-auth

Setup

First of all, prefer to run the package code on the back-end side of the electron. So the documentation will only refer directly to the main.ts file.

useMcuseMcAuth()

To use the package authentication system, you need to instatiate the Auth function.

import { Auth } from 'electron-mc-auth'

const mcAuth = useMcuseMcAuth()

This function should return an object containing all package functions with the predefined configuration passed on it initialization.

There are some functions that you can import directly, but, to start the auth flow, you should use launch() function that is returned by the useMcuseMcAuth() function.

Starting the auth flow

It's pretty straightfoward, just use the launch() function provided by the useMcuseMcAuth() function and it will handle the Window creation and network requests to get you authenticated and reuturn the MinecraftProfile object.

Here's an example on the main file of electron.

// /main.ts

app.whenReady().then(() => {
  createWindow()
  const authenticate = async () => {
    const { launch, refresh } = useMcAuth({...})
    const auth = await launch()

    if (!auth) return

    const refreshData = await refresh(auth)

    if (!refresh) return

    dialog.showMessageBox({
      message: `
      Logged as: ${auth.name}
    `
    })

    return true
  }
  authenticate()
})

The Minecraft profile object

This is the most important part of the package.

If the login is succesful, you should recieve an object like this;

export interface MinecraftProfileTypes {
  id: string
  name: string
  skins: {
    id: string
    state: string
    url: string
    variant: string
  }[]
  capes: {
    id: string
    state: string
    url: string
    alias: string
  }[]
  access_token: string
  refresh_token: string
  client_token: string
  expires_in: number
}

MCLC

Also, the package can convert its object to be compatible with MCLC package.

To do this, just pass your Minecraft Profile object to the getMCLC() function.

function getMCLC(profile: MinecraftProfileTypes): MCLCAuthTypes

Logging

You can pass your preffered callback for onError, onInfo, onWarn, onLog events

Example using default useMcAuth() function.

const { launch, getLink, login, getMCLC, refresh, validate, getMinecraft } =
  useMcAuth({
    onError: (msg) => {
      return msg
    }
  })

Here's the type definition for the callback;

export type LogFunctionTypes = (message: string) => void

export interface LoggerCallBackTypes {
  onError?: LogFunctionTypes
  onInfo?: LogFunctionTypes
  onWarn?: LogFunctionTypes
  onLog?: LogFunctionTypes
}