Skip to content

Commit

Permalink
Fixed re-auth on reload of launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Matwix committed Jan 18, 2021
1 parent 24dc4a7 commit c2a74ea
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 234 deletions.
3 changes: 2 additions & 1 deletion app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ body, button {
font-family: 'Avenir Medium';
font-size: 12px;
font-weight: bold;
margin-bottom: 3px;
margin-bottom: 253px;
margin-top: -250px;
color: rgba(255, 255, 255, 0.75);
}

Expand Down
32 changes: 12 additions & 20 deletions app/assets/js/authmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const loggerSuccess = LoggerUtil('%c[AuthManager]', 'color: #209b07; font-weight

// Validation

async function validateSelectedMojang() {
const current = ConfigManager.getSelectedAccount()
async function validateSelectedMojang(selectedAccount) {
const current = selectedAccount
const isValid = await Mojang.validate(current.accessToken, ConfigManager.getClientToken())
if(!isValid){
try {
Expand All @@ -42,9 +42,9 @@ async function validateSelectedMojang() {
}
}

async function validateSelectedMicrosoft() {
async function validateSelectedMicrosoft(selectedAccount) {
try {
const current = ConfigManager.getSelectedAccount()
const current = selectedAccount
const now = new Date().getTime()
const MCExpiresAt = Date.parse(current.expiresAt)
const MCExpired = now > MCExpiresAt
Expand Down Expand Up @@ -131,21 +131,14 @@ exports.removeAccount = async function(uuid){
* otherwise false.
*/
exports.validateSelected = async function(){
const current = ConfigManager.getSelectedAccount()
const isValid = await Mojang.validate(current.accessToken, ConfigManager.getClientToken())
if(!isValid){
try{
if (ConfigManager.getSelectedAccount() === 'microsoft') {
const validate = await validateSelectedMicrosoft()
return validate
} else {
const validate = await validateSelectedMojang()
return validate
}
} catch (error) {
return Promise.reject(error)
}
}
const selectedAccount = ConfigManager.getSelectedAccount()
if (selectedAccount.type === 'microsoft') {
const validate = await validateSelectedMicrosoft(selectedAccount)
return validate
} else {
const validate = await validateSelectedMojang(selectedAccount)
return validate
}
}

exports.addMSAccount = async authCode => {
Expand All @@ -156,7 +149,6 @@ exports.addMSAccount = async authCode => {
const MCProfile = await Microsoft.getMCProfile(MCAccessToken.access_token)
const ret = ConfigManager.addAuthAccount(MCProfile.id, MCAccessToken.access_token, MCProfile.name, MCProfile.name, MCAccessToken.expires_at, 'microsoft')
ConfigManager.save()

return ret
} catch(error) {
return Promise.reject(error)
Expand Down
26 changes: 13 additions & 13 deletions app/assets/js/mojang.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Mojang
*
*
* This module serves as a minimal wrapper for Mojang's REST api.
*
*
* @module mojang
*/
// Requirements
Expand Down Expand Up @@ -60,7 +60,7 @@ const statuses = [
* Converts a Mojang status color to a hex value. Valid statuses
* are 'green', 'yellow', 'red', and 'grey'. Grey is a custom status
* to our project which represents an unknown status.
*
*
* @param {string} status A valid status code.
* @returns {string} The hex color of the status code.
*/
Expand All @@ -83,7 +83,7 @@ exports.statusToHex = function(status){
* The response is condensed into a single object. Each service is
* a key, where the value is an object containing a status and name
* property.
*
*
* @see http://wiki.vg/Mojang_API#API_Status
*/
exports.status = function(){
Expand Down Expand Up @@ -122,13 +122,13 @@ exports.status = function(){

/**
* Authenticate a user with their Mojang credentials.
*
*
* @param {string} username The user's username, this is often an email.
* @param {string} password The user's password.
* @param {string} clientToken The launcher's Client Token.
* @param {boolean} requestUser Optional. Adds user object to the reponse.
* @param {Object} agent Optional. Provided by default. Adds user info to the response.
*
*
* @see http://wiki.vg/Authentication#Authenticate
*/
exports.authenticate = function(username, password, clientToken, requestUser = true, agent = minecraftAgent){
Expand Down Expand Up @@ -167,10 +167,10 @@ exports.authenticate = function(username, password, clientToken, requestUser = t
/**
* Validate an access token. This should always be done before launching.
* The client token should match the one used to create the access token.
*
*
* @param {string} accessToken The access token to validate.
* @param {string} clientToken The launcher's client token.
*
*
* @see http://wiki.vg/Authentication#Validate
*/
exports.validate = function(accessToken, clientToken){
Expand Down Expand Up @@ -202,10 +202,10 @@ exports.validate = function(accessToken, clientToken){
/**
* Invalidates an access token. The clientToken must match the
* token used to create the provided accessToken.
*
*
* @param {string} accessToken The access token to invalidate.
* @param {string} clientToken The launcher's client token.
*
*
* @see http://wiki.vg/Authentication#Invalidate
*/
exports.invalidate = function(accessToken, clientToken){
Expand Down Expand Up @@ -237,11 +237,11 @@ exports.invalidate = function(accessToken, clientToken){
* Refresh a user's authentication. This should be used to keep a user logged
* in without asking them for their credentials again. A new access token will
* be generated using a recent invalid access token. See Wiki for more info.
*
*
* @param {string} accessToken The old access token.
* @param {string} clientToken The launcher's client token.
* @param {boolean} requestUser Optional. Adds user object to the reponse.
*
*
* @see http://wiki.vg/Authentication#Refresh
*/
exports.refresh = function(accessToken, clientToken, requestUser = true){
Expand All @@ -268,4 +268,4 @@ exports.refresh = function(accessToken, clientToken, requestUser = true){
}
})
})
}
}
1 change: 1 addition & 0 deletions app/assets/js/scripts/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,4 @@ ipcRenderer.on('MSALoginWindowReply', (event, ...args) => {
toggleOverlay(true)
loggerLogin.error(error)
})
})
2 changes: 1 addition & 1 deletion app/landing.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</a>
</div>
<div class="mediaContainer" id="settingsMediaContainer">
<a href="https://discord.gg/Hd3ufCDCeg" class="mediaURL" id="discordURL">
<a href="https://discord.com/invite/MMy6GwY" class="mediaURL" id="discordURL">
<button class="mediaButton" id="discordMediaButton">
<svg id="discordSVG" class="mediaSVG" viewBox="35.34 34.3575 70.68 68.71500">
<g>
Expand Down
2 changes: 1 addition & 1 deletion app/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<form id="loginForm">
<img id="loginImageSeal" src="assets/images/SealCircle.png"/>
<span id="loginSubheader">MINECRAFT LOGIN</span>
<button id="loginMSButton">OR Microsoft Login</button>
<div class="loginFieldContainer">
<svg id="profileSVG" class="loginSVG" viewBox="40 37 65.36 61.43">
<g>
Expand Down Expand Up @@ -53,6 +52,7 @@
<!--<div class="spinningCircle" id="loginSpinner"></div>-->
</div>
</button>
<button id="loginMSButton">OR Microsoft Login</button>
<div id="loginDisclaimer">
<span class="loginSpanDim" id="loginRegisterSpan">
<a href="https://www.minecraft.net/en-us/store/minecraft-java-edition">Need an Account?</a>
Expand Down
Loading

0 comments on commit c2a74ea

Please sign in to comment.