Compare commits

..

6 Commits

12 changed files with 129 additions and 4141 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 MiB

View File

@ -16,7 +16,7 @@
}
body {
background-image: url(img/bg.png);
background-image: url(../../skirda/skirdaGoBackend/authskirda/templates/callback/img/bg.png);
background-repeat:no-repeat;
background-size: cover;
background-position: center center;
@ -150,7 +150,7 @@
<div id="loginSkirdaAuthorizationWindow" style="display: none;">
<div id="settingsAboutCurrentContent" class="Centered">
<div id="settingsAboutCurrentHeadline">
<img id="settingsAboutLogo" src="img/Logo.png">
<img id="settingsAboutLogo" src="../../skirda/skirdaGoBackend/authskirda/templates/callback/img/Logo.png">
<span id="settingsAboutTitle">Авторизация через Discord</span>
</div>
<div id="settingsAboutCurrentVersion">
@ -166,7 +166,7 @@
<div id="loginSkirdaAuthorizationWindow" >
<div id="settingsAboutCurrentContent" class="Centered">
<div id="settingsAboutCurrentHeadline">
<img id="settingsAboutLogo" src="img/Logo.png">
<img id="settingsAboutLogo" src="../../skirda/skirdaGoBackend/authskirda/templates/callback/img/Logo.png">
<span id="settingsAboutTitle">Авторизация через Discord</span>
</div>
<div id="settingsAboutCurrentVersion" class="Centered">

File diff suppressed because it is too large Load Diff

View File

@ -72,8 +72,9 @@ exports.addMojangAccount = async function(username, password){
* @param {string} skirdaToken
* */
exports.addSkirdaAccount = async function(uuid, accessToken, username, displayName, skirdaToken){
ConfigManager.addSkirdaAccount(uuid, accessToken, username, displayName, skirdaToken)
const ret = ConfigManager.addSkirdaAccount(uuid, accessToken, username, displayName, skirdaToken)
ConfigManager.save()
return ret
}
exports.addOfflineAccount = async function(usernameOffline){
@ -293,6 +294,40 @@ async function validateSelectedMojangAccount(){
}
}
}
// require('./scripts/loginSkirdaDiscord')
/**
* Validate the selected account with Skirda's authserver. If the account is not valid,
* we will attempt to refresh the access token and update that value. If that fails, a
* new login will be required.
*
* @returns {Promise.<boolean>} Promise which resolves to true if the access token is valid,
* otherwise false.
*/
async function validateSelectedSkirdaAccount(){
const current = ConfigManager.getSelectedAccount()
const result = await SkirdaDiscordAuth.ValidateAccount(current.accessToken)
// const response = await MojangRestAPI.validate(current.accessToken, ConfigManager.getClientToken())
// const isValid = response.data
if(!result){
const refreshResponse = await MojangRestAPI.refresh(current.accessToken, ConfigManager.getClientToken())
if(refreshResponse.responseStatus === RestResponseStatus.SUCCESS) {
const session = refreshResponse.data
ConfigManager.updateMojangAuthAccount(current.uuid, session.accessToken)
ConfigManager.save()
} else {
log.error('Error while validating selected profile:', refreshResponse.error)
log.info('Account access token is invalid.')
return false
}
log.info('Account access token validated.')
return true
} else {
log.info('Account access token validated.')
return true
}
}
/**
@ -367,10 +402,14 @@ async function validateSelectedMicrosoftAccount(){
exports.validateSelected = async function(){
const current = ConfigManager.getSelectedAccount()
if(current.type === 'microsoft') {
return await validateSelectedMicrosoftAccount()
} else {
return await validateSelectedMojangAccount()
switch (current.type) {
case 'mojang':
return await validateSelectedMojangAccount()
// break
case 'microsoft':
return await validateSelectedMicrosoftAccount()
// break
case 'skirda':
return await validateSelectedSkirdaAccount()
}
}

View File

@ -144,6 +144,7 @@ document.getElementById('avatarOverlay').onclick = async e => {
// Bind selected account
function updateSelectedAccount(authUser){
let username = Lang.queryJS('landing.selectedAccount.noAccountSelected')
console.log(authUser)
if(authUser != null){
if(authUser.displayName != null){
username = authUser.displayName
@ -245,7 +246,7 @@ const refreshServerStatus = async (fade = false) => {
try {
const servStat = await getServerStatus(47, serv.hostname, serv.port)
console.log(servStat)
// console.log(servStat)
pLabel = Lang.queryJS('landing.serverStatus.players')
pVal = servStat.players.online + '/' + servStat.players.max

View File

@ -2,8 +2,14 @@
// const fs = require('fs')
// const {addSkirdaAccount} = require('configmanager')
// const auth_api_url = 'http://192.168.88.10:8083'
// const auth_api_url = 'http://localhost:8083'
const auth_api_url = 'http://skirda-auth.brzezinski.ru'
function uuidv4() {
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
class SkirdaDiscordAuth{
/**
* @typedef {Object} DiscordRedirectAuth
@ -12,9 +18,9 @@ class SkirdaDiscordAuth{
*
* @return {Promise<DiscordRedirectAuth | string>}
* */
temp_installId = '26c175e2-71bd-4d80-9553-cc1575fc8ef9'
async Init(){
const resp = await fetch(`${auth_api_url}/v1/auth/discord/init?installId=${this.temp_installId}`)
static temp_installId = uuidv4()
static async Init(){
const resp = await fetch(`${auth_api_url}/v1/auth/discord/init?installId=${SkirdaDiscordAuth.temp_installId}`)
if (resp.statusCode !== 200){
return await resp.text()
@ -28,15 +34,13 @@ class SkirdaDiscordAuth{
// * @param timeout {number} Timeout to poll in seconds
* @return {SkirdaUserResp | string} Result of OAuth login
*/
async CyclePolling(requestId){
static async CyclePolling(requestId){
for (let i = 0; i < 15; i++) {
const resp = await this._poll(requestId)
// console.log(resp)
const resp = await SkirdaDiscordAuth._poll(requestId)
switch (resp.status){
case 204:
await this._sleep(4000)
await SkirdaDiscordAuth._sleep(4000)
continue
case 200:
return await resp.json()
@ -60,7 +64,7 @@ class SkirdaDiscordAuth{
* @param jwtToken {string} JWT Token for auth
* @return {YggProfile | string} Result of auth
*/
async YggdrasilAuth(jwtToken){
static async YggdrasilAuth(jwtToken){
const resp = await fetch(`${auth_api_url}/yggdrasil/skirda/authenticate`, {
headers:{
'Content-Type': 'application/json',
@ -85,49 +89,89 @@ class SkirdaDiscordAuth{
* @param requestId {string}
* @return {Response}
* */
async _poll(requestId){
const resp = await fetch(`${auth_api_url}/v1/auth/discord/periodicPolling?installId=${this.temp_installId}&requestId=${requestId}`)
return resp
static async _poll(requestId){
return await fetch(`${auth_api_url}/v1/auth/discord/periodicPolling?installId=${SkirdaDiscordAuth.temp_installId}&requestId=${requestId}`)
}
_sleepSetTimeout_ctrl
static _sleepSetTimeout_ctrl
/**
* @param ms {number}
* @return {boolean}
*/
async _sleep(ms) {
static async _sleep(ms) {
clearInterval(this._sleepSetTimeout_ctrl)
return new Promise(resolve => this._sleepSetTimeout_ctrl = setTimeout(resolve, ms))
}
static async ValidateAccount(jwtToken) {
const resp = await fetch(`${auth_api_url}/v1/auth/refresh`,{
headers:{
'Content-Type': 'application/json',
'Authorization': jwtToken
}
})
// console.log(resp, resp.statusCode)
return resp.status === 200
}
}
const skAuth = new SkirdaDiscordAuth()
// const skAuth = new SkirdaDiscordAuth()
const loginSkirdaDiscordButton = document.getElementById('loginSkirdaDiscordInitAuth')
/**
* @return boolean
* */
async function InitSkirdaDiscordLogin (){
const res = await skAuth.Init()
const res = await SkirdaDiscordAuth.Init()
let redir
try {
redir = JSON.parse(res)
} catch (e) {
SpawnError(Lang.queryJS('login.error.unknown'))
return
}
// console.log(redir)
const redir = JSON.parse(res) //FIXME
console.log(redir)
const resOpenUrl = await shell.openExternal(redir.redirectUrl)
const skirdaAuth = await skAuth.CyclePolling(redir.requestId)
const skirdaAuth = await SkirdaDiscordAuth.CyclePolling(redir.requestId)
//TODO validate resp
console.log(skirdaAuth)
// skirdaAuth.skirdaUserId = '2a5fd868-1ac5-4ccf-a22f-183822de2d61'
// console.log(skirdaAuth)
const yggAuth = await skAuth.YggdrasilAuth(skirdaAuth.token)
//TODO validate resp
const yggAuthRes = JSON.parse(yggAuth)
console.log(yggAuthRes)
if (typeof skirdaAuth.token !== 'string'){
SpawnError(Lang.queryJS('login.error.unknown'))
return
}
const yggAuth = await SkirdaDiscordAuth.YggdrasilAuth(skirdaAuth.token)
let yggAuthRes
try {
yggAuthRes = JSON.parse(yggAuth)
} catch (e) {
SpawnError(Lang.queryJS('login.error.unknown'))
return
}
// console.log(yggAuthRes)
AuthManager.addSkirdaAccount(yggAuthRes.profile.id, skirdaAuth.token, skirdaAuth.skirdaUserId, yggAuthRes.profile.name, skirdaAuth.token)
AuthManager.addSkirdaAccount(yggAuthRes.profile.id, skirdaAuth.token, skirdaAuth.skirdaUserId, yggAuthRes.profile.name, skirdaAuth.token).then((value) => {
updateSelectedAccount(value)
})
setTimeout(() => {
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)
}, 1000)
}
function SpawnError(actualDisplayableError){
setOverlayContent(actualDisplayableError.title, actualDisplayableError.desc, Lang.queryJS('login.tryAgain'))
setOverlayHandler(() => {
formDisabled(false)
toggleOverlay(false)
})
toggleOverlay(true)
}

View File

@ -667,7 +667,7 @@ function populateAuthAccounts(){
authKeys.forEach((val) => {
const acc = authAccounts[val]
console.log(acc)
// console.log(acc)
const accHtml = `<div class="settingsAuthAccount" uuid="${acc.uuid}">
<div class="settingsAuthAccountLeft">

View File

@ -79,9 +79,9 @@ async function showMainUI(data){
// If this is enabled in a development environment we'll get ratelimited.
// The relaunch frequency is usually far too high.
if(!isDev && isLoggedIn){
validateSelectedAccount()
}
// if(!isDev && isLoggedIn){
validateSelectedAccount()
// }
if(ConfigManager.isFirstLaunch()){
currentView = VIEWS.welcome

View File

@ -153,12 +153,12 @@ requiredValue = "* Требуется"
[js.login.error.unknown]
title = "Неизвестная ошибка при авторизации"
desc = "Произошла неизвестная ошибка. Проверте консоль для дополнительных деталей."
desc = "Произошла неизвестная ошибка. Проверте консоль (Ctrl + Shift + I) чтобы узнать, что случулось."
[js.landing.launch]
pleaseWait = "Пожалуйста, подождите..."
failureTitle = "Ошибка при запуске :("
failureText = "Сделайте скриншот из консоли (CTRL + Shift + i) и скажите Грише, что все пошло по пизде."
failureText = "Сделайте скриншот из консоли (CTRL + Shift + I) и скажите Грише, что все пошло по пизде."
okay = "Окей"
[js.landing.selectedAccount]

View File

@ -19,5 +19,5 @@
<div id="iframecontainer">
<iframe id="dynmapiframe" src="https://minemap.gregbrzezinski.com" frameborder="0"></iframe>
</div>
<script src="./assets/js/scripts/dynmap.js"></script>
<!-- <script src="./assets/js/scripts/dynmap.js"></script>-->
</div>

View File

@ -113,7 +113,7 @@
<div id="iframecontainer">
<iframe id="dynmapiframe" src="https://mc.westeroscraft.com/#" frameborder="0"></iframe>
</div>
<script src="./assets/js/scripts/dynmap.js"></script>
<!-- <script src="./assets/js/scripts/dynmap.js"></script>-->
</div>
<!-- <div id="newsContent" article="-1" style="display: none;">-->
<!-- <div id="newsStatusContainer">-->