Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienHH committed Aug 22, 2024
1 parent 03293e2 commit 64a25c5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/playfab/deviceCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (!username) {

async function doAuth () {
const flow = new Authflow(username, cacheDir, { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' })

const response = await flow.getPlayfabLogin()

console.log(response)
Expand Down
2 changes: 1 addition & 1 deletion examples/services/deviceCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (!username) {

async function doAuth () {
const flow = new Authflow(username, cacheDir, { authTitle: Titles.MinecraftNintendoSwitch, deviceType: 'Nintendo', flow: 'live' })

const response = await flow.getMinecraftServicesToken()

console.log(response)
Expand Down
2 changes: 1 addition & 1 deletion src/MicrosoftAuthFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class MicrosoftAuthFlow {
}
}

async getPlayfabLogin() {
async getPlayfabLogin () {
const cache = this.pfb.getCachedAccessToken()

if (cache.valid) {
Expand Down
18 changes: 8 additions & 10 deletions src/TokenManagers/MinecraftServicesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const { Endpoints } = require('../common/Constants')
const { checkStatus } = require('../common/Util')

class MinecraftServicesTokenManager {
constructor(cache) {
constructor (cache) {
this.cache = cache
}

async getCachedAccessToken() {
async getCachedAccessToken () {
const { mcs: token } = await this.cache.getCached()
debug('[mcs] token cache', token)

Expand All @@ -21,19 +21,18 @@ class MinecraftServicesTokenManager {
return { valid, until: expires, token: token.mcToken, data: token }
}

async setCachedToken(data) {
async setCachedToken (data) {
await this.cache.setCachedPartial(data)
}

async getAccessToken(sessionTicket, options = {}) {

async getAccessToken (sessionTicket, options = {}) {
const response = await fetch(Endpoints.MinecraftServicesSessionStart, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
device: {
applicationType: options.applicationType ?? 'MinecraftPE',
gameVersion: options.version ?? '1.20.62',
body: JSON.stringify({
device: {
applicationType: options.applicationType ?? 'MinecraftPE',
gameVersion: options.version ?? '1.20.62',
id: options.deviceId ?? 'c1681ad3-415e-30cd-abd3-3b8f51e771d1',
memory: options.deviceMemory ?? String(8 * (1024 * 1024 * 1024)),
platform: options.platform ?? 'Windows10',
Expand Down Expand Up @@ -61,7 +60,6 @@ class MinecraftServicesTokenManager {
await this.setCachedToken({ mcs: tokenResponse })

return response.result

}
}

Expand Down
6 changes: 2 additions & 4 deletions src/TokenManagers/PlayfabTokenManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ class PlayfabTokenManager {
if (!cache) return

const expires = new Date(cache.EntityToken.TokenExpiration)

const remaining = expires - Date.now()

const valid = remaining > 1000

return { valid, until: expires, data: cache }
}

async getAccessToken (xsts) {

const response = await fetch(Endpoints.PlayfabLoginWithXbox, {
method: 'post',
headers: { 'Content-Type': 'application/json' },
Expand Down Expand Up @@ -65,7 +64,6 @@ class PlayfabTokenManager {

return data.data
}

}

module.exports = PlayfabTokenManager

0 comments on commit 64a25c5

Please sign in to comment.