wwwwwwwwwwwwwww
This commit is contained in:
parent
a16b8a3643
commit
34bdf62bbd
@ -69,9 +69,10 @@ exports.addMojangAccount = async function(username, password){
|
||||
* @param {string} accessToken
|
||||
* @param {string} username
|
||||
* @param {string} displayName
|
||||
* @param {string} skirdaToken
|
||||
* */
|
||||
exports.addSkirdaAccount = async function(uuid, accessToken, username, displayName){
|
||||
ConfigManager.addSkirdaAccount(uuid, accessToken, username, displayName)
|
||||
exports.addSkirdaAccount = async function(uuid, accessToken, username, displayName, skirdaToken){
|
||||
ConfigManager.addSkirdaAccount(uuid, accessToken, username, displayName, skirdaToken)
|
||||
ConfigManager.save()
|
||||
}
|
||||
|
||||
|
@ -364,14 +364,15 @@ exports.addOfflineAccount = function(usernameOffline){
|
||||
return config.authenticationDatabase[fake_uuid]
|
||||
}
|
||||
|
||||
exports.addSkirdaAccount = function(uuid, accessToken, username, displayName){
|
||||
exports.addSkirdaAccount = function(uuid, accessToken, username, displayName, skirdaToken){
|
||||
config.selectedAccount = uuid
|
||||
config.authenticationDatabase[uuid] = {
|
||||
type: 'skirda',
|
||||
accessToken,
|
||||
username: username.trim(),
|
||||
uuid: uuid.trim(),
|
||||
displayName: displayName.trim()
|
||||
displayName: displayName.trim(),
|
||||
skirdaJWT: skirdaToken
|
||||
}
|
||||
return config.authenticationDatabase[uuid]
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
// const http = require('http')
|
||||
// const fs = require('fs')
|
||||
// const {addSkirdaAccount} = require('configmanager')
|
||||
// const auth_api_url = 'http://192.168.88.10:8083'
|
||||
const auth_api_url = 'http://skirda-auth.brzezinski.ru'
|
||||
const auth_api_url = 'http://192.168.88.10:8083'
|
||||
// const auth_api_url = 'http://skirda-auth.brzezinski.ru'
|
||||
|
||||
class SkirdaDiscordAuth{
|
||||
/**
|
||||
@ -44,13 +44,37 @@ class SkirdaDiscordAuth{
|
||||
console.error(await resp.text())
|
||||
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
|
||||
@ -80,28 +104,29 @@ class SkirdaDiscordAuth{
|
||||
|
||||
|
||||
|
||||
const auth = new SkirdaDiscordAuth()
|
||||
const skAuth = new SkirdaDiscordAuth()
|
||||
const loginSkirdaDiscordButton = document.getElementById('loginSkirdaDiscordInitAuth')
|
||||
|
||||
loginSkirdaDiscordButton.addEventListener('click', async () =>{
|
||||
const res = await auth.Init()
|
||||
const res = await skAuth.Init()
|
||||
|
||||
const redir = JSON.parse(res) //FIXME
|
||||
console.log(redir)
|
||||
const resOpenUrl = await shell.openExternal(redir.redirectUrl)
|
||||
|
||||
const skirdaAuth = await auth.CyclePolling(redir.requestId)
|
||||
// console.log(skirdaAuth)
|
||||
const skirdaAuth = await skAuth.CyclePolling(redir.requestId)
|
||||
//TODO validate resp
|
||||
console.log(skirdaAuth)
|
||||
// skirdaAuth.skirdaUserId = '2a5fd868-1ac5-4ccf-a22f-183822de2d61'
|
||||
|
||||
let account = {
|
||||
uuid: '2a5fd868-1ac5-4ccf-a22f-183822de2d61',
|
||||
token: '',
|
||||
username: skirdaAuth.skirdaUserId,
|
||||
displayName: skirdaAuth.username
|
||||
}
|
||||
const yggAuth = await skAuth.YggdrasilAuth(skirdaAuth.token)
|
||||
//TODO validate resp
|
||||
const yggAuthRes = JSON.parse(yggAuth)
|
||||
console.log(yggAuthRes)
|
||||
|
||||
|
||||
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(() => {
|
||||
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)
|
||||
|
Loading…
Reference in New Issue
Block a user