mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 03:32:12 -08:00
Implement friendly display of error codes if Microsoft authentication fails.
This commit is contained in:
parent
47aaee5214
commit
3b2d6cf76f
@ -13,7 +13,7 @@ const ConfigManager = require('./configmanager')
|
|||||||
const { LoggerUtil } = require('helios-core')
|
const { LoggerUtil } = require('helios-core')
|
||||||
const { RestResponseStatus } = require('helios-core/common')
|
const { RestResponseStatus } = require('helios-core/common')
|
||||||
const { MojangRestAPI, mojangErrorDisplayable, MojangErrorCode } = require('helios-core/mojang')
|
const { MojangRestAPI, mojangErrorDisplayable, MojangErrorCode } = require('helios-core/mojang')
|
||||||
const { MicrosoftAuth } = require('helios-core/microsoft')
|
const { MicrosoftAuth, microsoftErrorDisplayable, MicrosoftErrorCode } = require('helios-core/microsoft')
|
||||||
const { AZURE_CLIENT_ID } = require('./ipcconstants')
|
const { AZURE_CLIENT_ID } = require('./ipcconstants')
|
||||||
|
|
||||||
const log = LoggerUtil.getLogger('AuthManager')
|
const log = LoggerUtil.getLogger('AuthManager')
|
||||||
@ -71,48 +71,48 @@ const AUTH_MODE = { FULL: 0, MS_REFRESH: 1, MC_REFRESH: 2 }
|
|||||||
* @returns An object with all auth data. AccessToken object will be null when mode is MC_REFRESH.
|
* @returns An object with all auth data. AccessToken object will be null when mode is MC_REFRESH.
|
||||||
*/
|
*/
|
||||||
async function fullMicrosoftAuthFlow(entryCode, authMode) {
|
async function fullMicrosoftAuthFlow(entryCode, authMode) {
|
||||||
|
try {
|
||||||
|
|
||||||
let accessTokenRaw
|
let accessTokenRaw
|
||||||
let accessToken
|
let accessToken
|
||||||
if(authMode !== AUTH_MODE.MC_REFRESH) {
|
if(authMode !== AUTH_MODE.MC_REFRESH) {
|
||||||
const accessTokenResponse = await MicrosoftAuth.getAccessToken(entryCode, authMode === AUTH_MODE.MS_REFRESH, AZURE_CLIENT_ID)
|
const accessTokenResponse = await MicrosoftAuth.getAccessToken(entryCode, authMode === AUTH_MODE.MS_REFRESH, AZURE_CLIENT_ID)
|
||||||
if(accessTokenResponse.responseStatus === RestResponseStatus.ERROR) {
|
if(accessTokenResponse.responseStatus === RestResponseStatus.ERROR) {
|
||||||
// TODO Fail.
|
return Promise.reject(microsoftErrorDisplayable(accessTokenResponse.microsoftErrorCode))
|
||||||
return // TODO
|
}
|
||||||
|
accessToken = accessTokenResponse.data
|
||||||
|
accessTokenRaw = accessToken.access_token
|
||||||
|
} else {
|
||||||
|
accessTokenRaw = entryCode
|
||||||
}
|
}
|
||||||
accessToken = accessTokenResponse.data
|
|
||||||
accessTokenRaw = accessToken.access_token
|
const xblResponse = await MicrosoftAuth.getXBLToken(accessTokenRaw)
|
||||||
} else {
|
if(xblResponse.responseStatus === RestResponseStatus.ERROR) {
|
||||||
accessTokenRaw = entryCode
|
return Promise.reject(microsoftErrorDisplayable(xblResponse.microsoftErrorCode))
|
||||||
}
|
}
|
||||||
|
const xstsResonse = await MicrosoftAuth.getXSTSToken(xblResponse.data)
|
||||||
const xblResponse = await MicrosoftAuth.getXBLToken(accessTokenRaw)
|
if(xstsResonse.responseStatus === RestResponseStatus.ERROR) {
|
||||||
if(xblResponse.responseStatus === RestResponseStatus.ERROR) {
|
return Promise.reject(microsoftErrorDisplayable(xstsResonse.microsoftErrorCode))
|
||||||
// TODO Fail.
|
}
|
||||||
return // TODO
|
const mcTokenResponse = await MicrosoftAuth.getMCAccessToken(xstsResonse.data)
|
||||||
}
|
if(mcTokenResponse.responseStatus === RestResponseStatus.ERROR) {
|
||||||
const xstsResonse = await MicrosoftAuth.getXSTSToken(xblResponse.data)
|
return Promise.reject(microsoftErrorDisplayable(mcTokenResponse.microsoftErrorCode))
|
||||||
if(xstsResonse.responseStatus === RestResponseStatus.ERROR) {
|
}
|
||||||
// TODO Fail.
|
const mcProfileResponse = await MicrosoftAuth.getMCProfile(mcTokenResponse.data.access_token)
|
||||||
return // TODO
|
if(mcProfileResponse.responseStatus === RestResponseStatus.ERROR) {
|
||||||
}
|
return Promise.reject(microsoftErrorDisplayable(mcProfileResponse.microsoftErrorCode))
|
||||||
const mcTokenResponse = await MicrosoftAuth.getMCAccessToken(xstsResonse.data)
|
}
|
||||||
if(mcTokenResponse.responseStatus === RestResponseStatus.ERROR) {
|
return {
|
||||||
// TODO Fail.
|
accessToken,
|
||||||
return // TODO
|
accessTokenRaw,
|
||||||
}
|
xbl: xblResponse.data,
|
||||||
const mcProfileResponse = await MicrosoftAuth.getMCProfile(mcTokenResponse.data.access_token)
|
xsts: xstsResonse.data,
|
||||||
if(mcProfileResponse.responseStatus === RestResponseStatus.ERROR) {
|
mcToken: mcTokenResponse.data,
|
||||||
// TODO Fail.
|
mcProfile: mcProfileResponse.data
|
||||||
return // TODO
|
}
|
||||||
}
|
} catch(err) {
|
||||||
return {
|
log.error(err)
|
||||||
accessToken,
|
return Promise.reject(microsoftErrorDisplayable(MicrosoftErrorCode.UNKNOWN))
|
||||||
accessTokenRaw,
|
|
||||||
xbl: xblResponse.data,
|
|
||||||
xsts: xstsResonse.data,
|
|
||||||
mcToken: mcTokenResponse.data,
|
|
||||||
mcProfile: mcProfileResponse.data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ const { MojangRestAPI, getServerStatus } = require('helios-core/mojang')
|
|||||||
// Internal Requirements
|
// Internal Requirements
|
||||||
const DiscordWrapper = require('./assets/js/discordwrapper')
|
const DiscordWrapper = require('./assets/js/discordwrapper')
|
||||||
const ProcessBuilder = require('./assets/js/processbuilder')
|
const ProcessBuilder = require('./assets/js/processbuilder')
|
||||||
const { RestResponseStatus } = require('helios-core/common')
|
const { RestResponseStatus, isDisplayableError } = require('helios-core/common')
|
||||||
|
|
||||||
// Launch Elements
|
// Launch Elements
|
||||||
const launch_content = document.getElementById('launch_content')
|
const launch_content = document.getElementById('launch_content')
|
||||||
|
@ -214,13 +214,26 @@ loginButton.addEventListener('click', () => {
|
|||||||
}, 1000)
|
}, 1000)
|
||||||
}).catch((displayableError) => {
|
}).catch((displayableError) => {
|
||||||
loginLoading(false)
|
loginLoading(false)
|
||||||
setOverlayContent(displayableError.title, displayableError.desc, Lang.queryJS('login.tryAgain'))
|
|
||||||
|
let actualDisplayableError
|
||||||
|
if(isDisplayableError(displayableError)) {
|
||||||
|
msftLoginLogger.error('Error while logging in.', displayableError)
|
||||||
|
actualDisplayableError = displayableError
|
||||||
|
} else {
|
||||||
|
// Uh oh.
|
||||||
|
msftLoginLogger.error('Unhandled error during login.', displayableError)
|
||||||
|
actualDisplayableError = {
|
||||||
|
title: 'Unknown Error During Login',
|
||||||
|
desc: 'An unknown error has occurred. Please see the console for details.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setOverlayContent(actualDisplayableError.title, actualDisplayableError.desc, Lang.queryJS('login.tryAgain'))
|
||||||
setOverlayHandler(() => {
|
setOverlayHandler(() => {
|
||||||
formDisabled(false)
|
formDisabled(false)
|
||||||
toggleOverlay(false)
|
toggleOverlay(false)
|
||||||
})
|
})
|
||||||
toggleOverlay(true)
|
toggleOverlay(true)
|
||||||
loggerLogin.log('Error while logging in.', displayableError)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
@ -397,6 +397,29 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => {
|
|||||||
prepareSettings()
|
prepareSettings()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.catch((displayableError) => {
|
||||||
|
|
||||||
|
let actualDisplayableError
|
||||||
|
if(isDisplayableError(displayableError)) {
|
||||||
|
msftLoginLogger.error('Error while logging in.', displayableError)
|
||||||
|
actualDisplayableError = displayableError
|
||||||
|
} else {
|
||||||
|
// Uh oh.
|
||||||
|
msftLoginLogger.error('Unhandled error during login.', displayableError)
|
||||||
|
actualDisplayableError = {
|
||||||
|
title: 'Unknown Error During Login',
|
||||||
|
desc: 'An unknown error has occurred. Please see the console for details.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switchView(getCurrentView(), viewOnClose, 500, 500, () => {
|
||||||
|
setOverlayContent(actualDisplayableError.title, actualDisplayableError.desc, Lang.queryJS('login.tryAgain'))
|
||||||
|
setOverlayHandler(() => {
|
||||||
|
toggleOverlay(false)
|
||||||
|
})
|
||||||
|
toggleOverlay(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user