merge
This commit is contained in:
commit
c1d8dbed47
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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]
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,34 @@ class SkirdaDiscordAuth{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
@ -76,26 +104,28 @@ 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)
|
// AuthManager.addSkirdaAccount(account.uuid, account.token, account.username, account.displayName)
|
||||||
AuthManager.addSkirdaAccount(account.uuid, account.token, account.username, account.displayName)
|
AuthManager.addSkirdaAccount(account.uuid, account.token, account.username, account.displayName)
|
||||||
@ -104,4 +134,3 @@ loginSkirdaDiscordButton.addEventListener('click', async () =>{
|
|||||||
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)
|
switchView(VIEWS.loginSkirdaDiscord, VIEWS.landing, 500, 500)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user