Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/makis-san/electron-mc-auth

Display an electronJs window to authenticate Minecraft accounts through Xbox Live.
https://github.com/makis-san/electron-mc-auth

auth authentication electronjs mclc microsoft minecraft oauth xbox xbox-live xbox-live-oauth

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# electron-mc-auth


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

---



version

license

ko-fi



***

[Getting started](#getting-started) | [MCLC](#mclc) | [Contribuittions](/#)

# Getting started

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

```shell
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.

```ts
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.

```ts
// /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;

```ts
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](https://www.npmjs.com/package/minecraft-launcher-core) package.

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

```ts
function getMCLC(profile: MinecraftProfileTypes): MCLCAuthTypes
```

## Logging

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

Example using default `useMcAuth()` function.

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

Here's the type definition for the callback;

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

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