Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/makis-san/electron-mc-auth
- Owner: makis-san
- License: mit
- Created: 2022-06-22T01:15:30.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-23T17:43:33.000Z (about 2 years ago)
- Last Synced: 2024-09-29T01:40:39.325Z (3 months ago)
- Topics: auth, authentication, electronjs, mclc, microsoft, minecraft, oauth, xbox, xbox-live, xbox-live-oauth
- Language: TypeScript
- Homepage:
- Size: 152 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# electron-mc-auth
Display an electronJs window to authenticate Minecraft accounts through Xbox Live.---
***
[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-author
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.tsapp.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) => voidexport interface LoggerCallBackTypes {
onError?: LogFunctionTypes
onInfo?: LogFunctionTypes
onWarn?: LogFunctionTypes
onLog?: LogFunctionTypes
}
```