Anrdoid: add 'getToken' to OSM Connection

This commit is contained in:
Pieter Vander Vennet 2025-02-05 13:20:51 +01:00
parent f25f5f156d
commit 3ec83483d8
2 changed files with 36 additions and 8 deletions

View file

@ -278,7 +278,7 @@ export class OsmConnection {
Utils.runningFromConsole ? undefined : window.location.href,
)
this.auth.authenticate((err, result) => {
this.auth.authenticate((err) => {
if (!err) {
this.loadUserInfo()
}
@ -564,16 +564,24 @@ export class OsmConnection {
/**
* To be called by land.html
*/
public finishLogin(callback: (previousURL: string, oauth_token: string) => void) {
public finishLogin(callback: (previousURL: string) => void) {
this.auth.authenticate(() => {
// Fully authed at this point
console.log("Authentication successful!")
const oauth_token = QueryParameters.GetQueryParameter("oauth_token", undefined).data ?? window.localStorage.getItem(this._oauth_config.url + "oauth2_access_token")
const previousLocation = LocalStorageSource.get("location_before_login")
callback(previousLocation.data, oauth_token)
callback(previousLocation.data)
})
}
public getToken(): string {
// https://www.openstreetmap.orgoauth2_access_token
let prefix = this.Backend()
while(prefix.endsWith("/")){
prefix = prefix.substring(0, prefix.length-2)
}
return QueryParameters.GetQueryParameter(prefix+ "oauth_token", undefined).data ?? window.localStorage.getItem(this._oauth_config.url + "oauth2_access_token")
}
private async loginAndroidPolyfill() {
const token = await AndroidPolyfill.requestLoginCodes()
console.log("Got login token!", token)