2024-12-31 16:31:01 +01:00
|
|
|
import { OsmConnection } from "../src/Logic/Osm/OsmConnection"
|
|
|
|
import Constants from "../src/Models/Constants"
|
2024-12-31 19:55:08 +01:00
|
|
|
import { Utils } from "../src/Utils"
|
|
|
|
import { UIEventSource } from "../src/Logic/UIEventSource"
|
|
|
|
import { VariableUiElement } from "../src/UI/Base/VariableUIElement"
|
2025-02-05 13:20:51 +01:00
|
|
|
import Combine from "../src/UI/Base/Combine"
|
2024-12-31 16:31:01 +01:00
|
|
|
|
|
|
|
console.log("Authorizing...")
|
|
|
|
const key = Constants.osmAuthConfig.url + "oauth2_state"
|
2025-01-22 02:22:53 +01:00
|
|
|
const st = window.localStorage.getItem(key)
|
|
|
|
console.log("Prev state is", key, st)
|
2024-12-31 19:55:08 +01:00
|
|
|
const tokenSrc = new UIEventSource("")
|
2025-02-05 13:20:51 +01:00
|
|
|
const debug = new UIEventSource<string[]>([])
|
2025-01-22 02:22:53 +01:00
|
|
|
|
2025-02-05 13:20:51 +01:00
|
|
|
new Combine([
|
|
|
|
new VariableUiElement(debug.map(debug => "<ul><li>"+debug.join("</li><li>")+"</li></ul>")),
|
|
|
|
new VariableUiElement(tokenSrc)]).AttachTo("token")
|
2025-01-22 02:22:53 +01:00
|
|
|
|
2025-02-05 13:20:51 +01:00
|
|
|
|
|
|
|
const connection = new OsmConnection()
|
|
|
|
connection.finishLogin(async () => {
|
|
|
|
let token: string = undefined
|
|
|
|
let attempt = 0
|
|
|
|
do {
|
|
|
|
await Utils.waitFor(500)
|
|
|
|
token = connection.getToken()
|
|
|
|
tokenSrc.set("Trying to get token ("+attempt+")")
|
|
|
|
attempt++
|
|
|
|
|
|
|
|
const dbg = []
|
|
|
|
Object.keys(localStorage).forEach(key => {
|
|
|
|
dbg.push(`${key} - ${localStorage.getItem(key)}`);
|
|
|
|
})
|
|
|
|
debug.set(dbg)
|
|
|
|
|
2025-02-05 18:21:50 +01:00
|
|
|
if(attempt > 10){
|
|
|
|
window.location.reload()
|
|
|
|
}
|
2025-02-05 13:20:51 +01:00
|
|
|
} while (!token)
|
2025-01-22 02:22:53 +01:00
|
|
|
console.log("Login finished, redirecting to passthrough; token is " + token)
|
2025-01-21 21:06:50 +01:00
|
|
|
tokenSrc.set(token)
|
2025-02-05 13:20:51 +01:00
|
|
|
if (!token) {
|
2025-01-22 18:20:28 +01:00
|
|
|
tokenSrc.set("ERROR: no token retrieved!")
|
|
|
|
return
|
|
|
|
}
|
2025-01-22 02:22:53 +01:00
|
|
|
window.location.href = "orgmapcomplete://passthrough.html?oauth_token=" + token
|
2024-12-31 16:31:01 +01:00
|
|
|
})
|