wwwwwwwwwwwwwww

This commit is contained in:
cyber-dream 2024-01-13 20:54:43 +03:00
parent a16b8a3643
commit 34bdf62bbd
3 changed files with 48 additions and 21 deletions

View File

@ -69,9 +69,10 @@ exports.addMojangAccount = async function(username, password){
* @param {string} accessToken * @param {string} accessToken
* @param {string} username * @param {string} username
* @param {string} displayName * @param {string} displayName
* @param {string} skirdaToken
* */ * */
exports.addSkirdaAccount = async function(uuid, accessToken, username, displayName){ exports.addSkirdaAccount = async function(uuid, accessToken, username, displayName, skirdaToken){
ConfigManager.addSkirdaAccount(uuid, accessToken, username, displayName) ConfigManager.addSkirdaAccount(uuid, accessToken, username, displayName, skirdaToken)
ConfigManager.save() ConfigManager.save()
} }

View File

@ -364,14 +364,15 @@ exports.addOfflineAccount = function(usernameOffline){
return config.authenticationDatabase[fake_uuid] return config.authenticationDatabase[fake_uuid]
} }
exports.addSkirdaAccount = function(uuid, accessToken, username, displayName){ exports.addSkirdaAccount = function(uuid, accessToken, username, displayName, skirdaToken){
config.selectedAccount = uuid config.selectedAccount = uuid
config.authenticationDatabase[uuid] = { config.authenticationDatabase[uuid] = {
type: 'skirda', type: 'skirda',
accessToken, accessToken,
username: username.trim(), username: username.trim(),
uuid: uuid.trim(), uuid: uuid.trim(),
displayName: displayName.trim() displayName: displayName.trim(),
skirdaJWT: skirdaToken
} }
return config.authenticationDatabase[uuid] return config.authenticationDatabase[uuid]
} }

View File

@ -1,8 +1,8 @@
// const http = require('http') // const http = require('http')
// 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://skirda-auth.brzezinski.ru' // const auth_api_url = 'http://skirda-auth.brzezinski.ru'
class SkirdaDiscordAuth{ class SkirdaDiscordAuth{
/** /**
@ -44,13 +44,37 @@ class SkirdaDiscordAuth{
console.error(await resp.text()) console.error(await resp.text())
return 'TODO error' return 'TODO error'
} }
} }
} }
/**
* @typedef {Object} SkYggAuthResponse
* @property {string} ClientToken
* @property {string} AccessToken
* @property {YggProfile} Profile
*
* @typedef {Object} YggProfile
* @property {string} name
* @property {string} UUID
*
* @param jwtToken {string} JWT Token for auth
* @return {YggProfile | string} Result of auth
*/
async YggdrasilAuth(jwtToken){
const resp = await fetch(`${auth_api_url}/yggdrasil/skirda/authenticate`, {
headers:{
'Content-Type': 'application/json',
'Authorization': jwtToken
}
})
if (resp.statusCode !== 200){
return await resp.text()
}
return await resp.json()
}
/** /**
* @typedef {Object} SkirdaUserResp * @typedef {Object} SkirdaUserResp
@ -80,28 +104,29 @@ class SkirdaDiscordAuth{
const auth = new SkirdaDiscordAuth() const skAuth = new SkirdaDiscordAuth()
const loginSkirdaDiscordButton = document.getElementById('loginSkirdaDiscordInitAuth') const loginSkirdaDiscordButton = document.getElementById('loginSkirdaDiscordInitAuth')
loginSkirdaDiscordButton.addEventListener('click', async () =>{ loginSkirdaDiscordButton.addEventListener('click', async () =>{
const res = await auth.Init() const res = await skAuth.Init()
const redir = JSON.parse(res) //FIXME const redir = JSON.parse(res) //FIXME
console.log(redir) console.log(redir)
const resOpenUrl = await shell.openExternal(redir.redirectUrl) const resOpenUrl = await shell.openExternal(redir.redirectUrl)
const skirdaAuth = await auth.CyclePolling(redir.requestId) const skirdaAuth = await skAuth.CyclePolling(redir.requestId)
// console.log(skirdaAuth) //TODO validate resp
console.log(skirdaAuth)
// skirdaAuth.skirdaUserId = '2a5fd868-1ac5-4ccf-a22f-183822de2d61' // skirdaAuth.skirdaUserId = '2a5fd868-1ac5-4ccf-a22f-183822de2d61'
let account = { const yggAuth = await skAuth.YggdrasilAuth(skirdaAuth.token)
uuid: '2a5fd868-1ac5-4ccf-a22f-183822de2d61', //TODO validate resp
token: '', const yggAuthRes = JSON.parse(yggAuth)
username: skirdaAuth.skirdaUserId, console.log(yggAuthRes)
displayName: skirdaAuth.username
}
AuthManager.addSkirdaAccount(yggAuthRes.profile.id, yggAuthRes.accessToken, skirdaAuth.skirdaUserId, yggAuthRes.profile.name, skirdaAuth.token)
AuthManager.addSkirdaAccount(account.uuid, account.token, account.username, account.displayName)
setTimeout(() => { setTimeout(() => {
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500) switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)