Compare commits
6 Commits
0795219071
...
f39b26a4ff
Author | SHA1 | Date | |
---|---|---|---|
f39b26a4ff | |||
7dcbc4c907 | |||
f768ce99e7 | |||
4089c9a47c | |||
9e078df32a | |||
494b221638 |
Binary file not shown.
Before Width: | Height: | Size: 142 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.7 MiB |
@ -16,7 +16,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-image: url(img/bg.png);
|
background-image: url(../../skirda/skirdaGoBackend/authskirda/templates/callback/img/bg.png);
|
||||||
background-repeat:no-repeat;
|
background-repeat:no-repeat;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center center;
|
background-position: center center;
|
||||||
@ -150,7 +150,7 @@
|
|||||||
<div id="loginSkirdaAuthorizationWindow" style="display: none;">
|
<div id="loginSkirdaAuthorizationWindow" style="display: none;">
|
||||||
<div id="settingsAboutCurrentContent" class="Centered">
|
<div id="settingsAboutCurrentContent" class="Centered">
|
||||||
<div id="settingsAboutCurrentHeadline">
|
<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>
|
<span id="settingsAboutTitle">Авторизация через Discord</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="settingsAboutCurrentVersion">
|
<div id="settingsAboutCurrentVersion">
|
||||||
@ -166,7 +166,7 @@
|
|||||||
<div id="loginSkirdaAuthorizationWindow" >
|
<div id="loginSkirdaAuthorizationWindow" >
|
||||||
<div id="settingsAboutCurrentContent" class="Centered">
|
<div id="settingsAboutCurrentContent" class="Centered">
|
||||||
<div id="settingsAboutCurrentHeadline">
|
<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>
|
<span id="settingsAboutTitle">Авторизация через Discord</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="settingsAboutCurrentVersion" class="Centered">
|
<div id="settingsAboutCurrentVersion" class="Centered">
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -72,8 +72,9 @@ exports.addMojangAccount = async function(username, password){
|
|||||||
* @param {string} skirdaToken
|
* @param {string} skirdaToken
|
||||||
* */
|
* */
|
||||||
exports.addSkirdaAccount = async function(uuid, accessToken, username, displayName, 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()
|
ConfigManager.save()
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.addOfflineAccount = async function(usernameOffline){
|
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(){
|
exports.validateSelected = async function(){
|
||||||
const current = ConfigManager.getSelectedAccount()
|
const current = ConfigManager.getSelectedAccount()
|
||||||
|
|
||||||
if(current.type === 'microsoft') {
|
switch (current.type) {
|
||||||
return await validateSelectedMicrosoftAccount()
|
case 'mojang':
|
||||||
} else {
|
|
||||||
return await validateSelectedMojangAccount()
|
return await validateSelectedMojangAccount()
|
||||||
|
// break
|
||||||
|
case 'microsoft':
|
||||||
|
return await validateSelectedMicrosoftAccount()
|
||||||
|
// break
|
||||||
|
case 'skirda':
|
||||||
|
return await validateSelectedSkirdaAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,7 @@ document.getElementById('avatarOverlay').onclick = async e => {
|
|||||||
// Bind selected account
|
// Bind selected account
|
||||||
function updateSelectedAccount(authUser){
|
function updateSelectedAccount(authUser){
|
||||||
let username = Lang.queryJS('landing.selectedAccount.noAccountSelected')
|
let username = Lang.queryJS('landing.selectedAccount.noAccountSelected')
|
||||||
|
console.log(authUser)
|
||||||
if(authUser != null){
|
if(authUser != null){
|
||||||
if(authUser.displayName != null){
|
if(authUser.displayName != null){
|
||||||
username = authUser.displayName
|
username = authUser.displayName
|
||||||
@ -245,7 +246,7 @@ const refreshServerStatus = async (fade = false) => {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
const servStat = await getServerStatus(47, serv.hostname, serv.port)
|
const servStat = await getServerStatus(47, serv.hostname, serv.port)
|
||||||
console.log(servStat)
|
// console.log(servStat)
|
||||||
pLabel = Lang.queryJS('landing.serverStatus.players')
|
pLabel = Lang.queryJS('landing.serverStatus.players')
|
||||||
pVal = servStat.players.online + '/' + servStat.players.max
|
pVal = servStat.players.online + '/' + servStat.players.max
|
||||||
|
|
||||||
|
@ -2,8 +2,14 @@
|
|||||||
// const fs = require('fs')
|
// const fs = require('fs')
|
||||||
// const {addSkirdaAccount} = require('configmanager')
|
// const {addSkirdaAccount} = require('configmanager')
|
||||||
// const auth_api_url = 'http://192.168.88.10:8083'
|
// 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'
|
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{
|
class SkirdaDiscordAuth{
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} DiscordRedirectAuth
|
* @typedef {Object} DiscordRedirectAuth
|
||||||
@ -12,9 +18,9 @@ class SkirdaDiscordAuth{
|
|||||||
*
|
*
|
||||||
* @return {Promise<DiscordRedirectAuth | string>}
|
* @return {Promise<DiscordRedirectAuth | string>}
|
||||||
* */
|
* */
|
||||||
temp_installId = '26c175e2-71bd-4d80-9553-cc1575fc8ef9'
|
static temp_installId = uuidv4()
|
||||||
async Init(){
|
static async Init(){
|
||||||
const resp = await fetch(`${auth_api_url}/v1/auth/discord/init?installId=${this.temp_installId}`)
|
const resp = await fetch(`${auth_api_url}/v1/auth/discord/init?installId=${SkirdaDiscordAuth.temp_installId}`)
|
||||||
|
|
||||||
if (resp.statusCode !== 200){
|
if (resp.statusCode !== 200){
|
||||||
return await resp.text()
|
return await resp.text()
|
||||||
@ -28,15 +34,13 @@ class SkirdaDiscordAuth{
|
|||||||
// * @param timeout {number} Timeout to poll in seconds
|
// * @param timeout {number} Timeout to poll in seconds
|
||||||
* @return {SkirdaUserResp | string} Result of OAuth login
|
* @return {SkirdaUserResp | string} Result of OAuth login
|
||||||
*/
|
*/
|
||||||
async CyclePolling(requestId){
|
static async CyclePolling(requestId){
|
||||||
for (let i = 0; i < 15; i++) {
|
for (let i = 0; i < 15; i++) {
|
||||||
const resp = await this._poll(requestId)
|
const resp = await SkirdaDiscordAuth._poll(requestId)
|
||||||
|
|
||||||
// console.log(resp)
|
|
||||||
|
|
||||||
switch (resp.status){
|
switch (resp.status){
|
||||||
case 204:
|
case 204:
|
||||||
await this._sleep(4000)
|
await SkirdaDiscordAuth._sleep(4000)
|
||||||
continue
|
continue
|
||||||
case 200:
|
case 200:
|
||||||
return await resp.json()
|
return await resp.json()
|
||||||
@ -60,7 +64,7 @@ class SkirdaDiscordAuth{
|
|||||||
* @param jwtToken {string} JWT Token for auth
|
* @param jwtToken {string} JWT Token for auth
|
||||||
* @return {YggProfile | string} Result of auth
|
* @return {YggProfile | string} Result of auth
|
||||||
*/
|
*/
|
||||||
async YggdrasilAuth(jwtToken){
|
static async YggdrasilAuth(jwtToken){
|
||||||
const resp = await fetch(`${auth_api_url}/yggdrasil/skirda/authenticate`, {
|
const resp = await fetch(`${auth_api_url}/yggdrasil/skirda/authenticate`, {
|
||||||
headers:{
|
headers:{
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -85,49 +89,89 @@ class SkirdaDiscordAuth{
|
|||||||
* @param requestId {string}
|
* @param requestId {string}
|
||||||
* @return {Response}
|
* @return {Response}
|
||||||
* */
|
* */
|
||||||
async _poll(requestId){
|
static async _poll(requestId){
|
||||||
const resp = await fetch(`${auth_api_url}/v1/auth/discord/periodicPolling?installId=${this.temp_installId}&requestId=${requestId}`)
|
return await fetch(`${auth_api_url}/v1/auth/discord/periodicPolling?installId=${SkirdaDiscordAuth.temp_installId}&requestId=${requestId}`)
|
||||||
return resp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sleepSetTimeout_ctrl
|
static _sleepSetTimeout_ctrl
|
||||||
/**
|
/**
|
||||||
* @param ms {number}
|
* @param ms {number}
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
async _sleep(ms) {
|
static async _sleep(ms) {
|
||||||
clearInterval(this._sleepSetTimeout_ctrl)
|
clearInterval(this._sleepSetTimeout_ctrl)
|
||||||
return new Promise(resolve => this._sleepSetTimeout_ctrl = setTimeout(resolve, ms))
|
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')
|
const loginSkirdaDiscordButton = document.getElementById('loginSkirdaDiscordInitAuth')
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
* */
|
||||||
async function InitSkirdaDiscordLogin (){
|
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 resOpenUrl = await shell.openExternal(redir.redirectUrl)
|
||||||
|
|
||||||
const skirdaAuth = await skAuth.CyclePolling(redir.requestId)
|
const skirdaAuth = await SkirdaDiscordAuth.CyclePolling(redir.requestId)
|
||||||
//TODO validate resp
|
//TODO validate resp
|
||||||
console.log(skirdaAuth)
|
// console.log(skirdaAuth)
|
||||||
// skirdaAuth.skirdaUserId = '2a5fd868-1ac5-4ccf-a22f-183822de2d61'
|
|
||||||
|
|
||||||
const yggAuth = await skAuth.YggdrasilAuth(skirdaAuth.token)
|
if (typeof skirdaAuth.token !== 'string'){
|
||||||
//TODO validate resp
|
SpawnError(Lang.queryJS('login.error.unknown'))
|
||||||
const yggAuthRes = JSON.parse(yggAuth)
|
return
|
||||||
console.log(yggAuthRes)
|
}
|
||||||
|
|
||||||
|
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(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)
|
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SpawnError(actualDisplayableError){
|
||||||
|
setOverlayContent(actualDisplayableError.title, actualDisplayableError.desc, Lang.queryJS('login.tryAgain'))
|
||||||
|
setOverlayHandler(() => {
|
||||||
|
formDisabled(false)
|
||||||
|
toggleOverlay(false)
|
||||||
|
})
|
||||||
|
toggleOverlay(true)
|
||||||
|
}
|
@ -667,7 +667,7 @@ function populateAuthAccounts(){
|
|||||||
|
|
||||||
authKeys.forEach((val) => {
|
authKeys.forEach((val) => {
|
||||||
const acc = authAccounts[val]
|
const acc = authAccounts[val]
|
||||||
console.log(acc)
|
// console.log(acc)
|
||||||
|
|
||||||
const accHtml = `<div class="settingsAuthAccount" uuid="${acc.uuid}">
|
const accHtml = `<div class="settingsAuthAccount" uuid="${acc.uuid}">
|
||||||
<div class="settingsAuthAccountLeft">
|
<div class="settingsAuthAccountLeft">
|
||||||
|
@ -79,9 +79,9 @@ async function showMainUI(data){
|
|||||||
|
|
||||||
// If this is enabled in a development environment we'll get ratelimited.
|
// If this is enabled in a development environment we'll get ratelimited.
|
||||||
// The relaunch frequency is usually far too high.
|
// The relaunch frequency is usually far too high.
|
||||||
if(!isDev && isLoggedIn){
|
// if(!isDev && isLoggedIn){
|
||||||
validateSelectedAccount()
|
validateSelectedAccount()
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(ConfigManager.isFirstLaunch()){
|
if(ConfigManager.isFirstLaunch()){
|
||||||
currentView = VIEWS.welcome
|
currentView = VIEWS.welcome
|
||||||
|
@ -153,12 +153,12 @@ requiredValue = "* Требуется"
|
|||||||
|
|
||||||
[js.login.error.unknown]
|
[js.login.error.unknown]
|
||||||
title = "Неизвестная ошибка при авторизации"
|
title = "Неизвестная ошибка при авторизации"
|
||||||
desc = "Произошла неизвестная ошибка. Проверте консоль для дополнительных деталей."
|
desc = "Произошла неизвестная ошибка. Проверте консоль (Ctrl + Shift + I) чтобы узнать, что случулось."
|
||||||
|
|
||||||
[js.landing.launch]
|
[js.landing.launch]
|
||||||
pleaseWait = "Пожалуйста, подождите..."
|
pleaseWait = "Пожалуйста, подождите..."
|
||||||
failureTitle = "Ошибка при запуске :("
|
failureTitle = "Ошибка при запуске :("
|
||||||
failureText = "Сделайте скриншот из консоли (CTRL + Shift + i) и скажите Грише, что все пошло по пизде."
|
failureText = "Сделайте скриншот из консоли (CTRL + Shift + I) и скажите Грише, что все пошло по пизде."
|
||||||
okay = "Окей"
|
okay = "Окей"
|
||||||
|
|
||||||
[js.landing.selectedAccount]
|
[js.landing.selectedAccount]
|
||||||
|
@ -19,5 +19,5 @@
|
|||||||
<div id="iframecontainer">
|
<div id="iframecontainer">
|
||||||
<iframe id="dynmapiframe" src="https://minemap.gregbrzezinski.com" frameborder="0"></iframe>
|
<iframe id="dynmapiframe" src="https://minemap.gregbrzezinski.com" frameborder="0"></iframe>
|
||||||
</div>
|
</div>
|
||||||
<script src="./assets/js/scripts/dynmap.js"></script>
|
<!-- <script src="./assets/js/scripts/dynmap.js"></script>-->
|
||||||
</div>
|
</div>
|
@ -113,7 +113,7 @@
|
|||||||
<div id="iframecontainer">
|
<div id="iframecontainer">
|
||||||
<iframe id="dynmapiframe" src="https://mc.westeroscraft.com/#" frameborder="0"></iframe>
|
<iframe id="dynmapiframe" src="https://mc.westeroscraft.com/#" frameborder="0"></iframe>
|
||||||
</div>
|
</div>
|
||||||
<script src="./assets/js/scripts/dynmap.js"></script>
|
<!-- <script src="./assets/js/scripts/dynmap.js"></script>-->
|
||||||
</div>
|
</div>
|
||||||
<!-- <div id="newsContent" article="-1" style="display: none;">-->
|
<!-- <div id="newsContent" article="-1" style="display: none;">-->
|
||||||
<!-- <div id="newsStatusContainer">-->
|
<!-- <div id="newsStatusContainer">-->
|
||||||
|
Loading…
Reference in New Issue
Block a user