Implement friendly display of error codes if Microsoft authentication fails.

This commit is contained in:
Daniel Scalzi 2022-02-09 20:52:57 -05:00
parent 47aaee5214
commit 3b2d6cf76f
No known key found for this signature in database
GPG Key ID: 9E3E2AFE45328AA5
4 changed files with 80 additions and 44 deletions

View File

@ -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,14 +71,14 @@ 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 accessToken = accessTokenResponse.data
accessTokenRaw = accessToken.access_token accessTokenRaw = accessToken.access_token
@ -88,23 +88,19 @@ async function fullMicrosoftAuthFlow(entryCode, authMode) {
const xblResponse = await MicrosoftAuth.getXBLToken(accessTokenRaw) const xblResponse = await MicrosoftAuth.getXBLToken(accessTokenRaw)
if(xblResponse.responseStatus === RestResponseStatus.ERROR) { if(xblResponse.responseStatus === RestResponseStatus.ERROR) {
// TODO Fail. return Promise.reject(microsoftErrorDisplayable(xblResponse.microsoftErrorCode))
return // TODO
} }
const xstsResonse = await MicrosoftAuth.getXSTSToken(xblResponse.data) const xstsResonse = await MicrosoftAuth.getXSTSToken(xblResponse.data)
if(xstsResonse.responseStatus === RestResponseStatus.ERROR) { if(xstsResonse.responseStatus === RestResponseStatus.ERROR) {
// TODO Fail. return Promise.reject(microsoftErrorDisplayable(xstsResonse.microsoftErrorCode))
return // TODO
} }
const mcTokenResponse = await MicrosoftAuth.getMCAccessToken(xstsResonse.data) const mcTokenResponse = await MicrosoftAuth.getMCAccessToken(xstsResonse.data)
if(mcTokenResponse.responseStatus === RestResponseStatus.ERROR) { if(mcTokenResponse.responseStatus === RestResponseStatus.ERROR) {
// TODO Fail. return Promise.reject(microsoftErrorDisplayable(mcTokenResponse.microsoftErrorCode))
return // TODO
} }
const mcProfileResponse = await MicrosoftAuth.getMCProfile(mcTokenResponse.data.access_token) const mcProfileResponse = await MicrosoftAuth.getMCProfile(mcTokenResponse.data.access_token)
if(mcProfileResponse.responseStatus === RestResponseStatus.ERROR) { if(mcProfileResponse.responseStatus === RestResponseStatus.ERROR) {
// TODO Fail. return Promise.reject(microsoftErrorDisplayable(mcProfileResponse.microsoftErrorCode))
return // TODO
} }
return { return {
accessToken, accessToken,
@ -114,6 +110,10 @@ async function fullMicrosoftAuthFlow(entryCode, authMode) {
mcToken: mcTokenResponse.data, mcToken: mcTokenResponse.data,
mcProfile: mcProfileResponse.data mcProfile: mcProfileResponse.data
} }
} catch(err) {
log.error(err)
return Promise.reject(microsoftErrorDisplayable(MicrosoftErrorCode.UNKNOWN))
}
} }
/** /**

View File

@ -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')

View File

@ -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)
}) })
}) })

View File

@ -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)
})
})
} }
} }
}) })