UX: allow to share login tokens via QR-code for educational context

This commit is contained in:
Pieter Vander Vennet 2025-05-29 23:26:59 +02:00
parent 93c613aa89
commit a90387c4f3
6 changed files with 123 additions and 48 deletions

View file

@ -154,7 +154,8 @@ export class OsmConnection {
constructor(options?: {
dryRun?: Store<boolean>
fakeUser?: false | boolean
oauth_token?: UIEventSource<string>
oauth_token?: UIEventSource<string>,
shared_cookie?: string,
// Used to keep multiple changesets open and to write to the correct changeset
singlePage?: boolean
attemptLogin?: boolean
@ -205,6 +206,10 @@ export class OsmConnection {
this._dryRun = options.dryRun ?? new UIEventSource<boolean>(false)
if (options?.shared_cookie) {
this.setToken(options?.shared_cookie)
}
this.updateAuthObject(false)
AndroidPolyfill.inAndroid.addCallback(() => {
this.updateAuthObject(false)
@ -600,6 +605,9 @@ export class OsmConnection {
})
}
/**
* Gets the login token. Sharing this will allow to mimic the user session on another device
*/
public getToken(): string {
// https://www.openstreetmap.orgoauth2_access_token
let prefix = this.Backend()
@ -608,12 +616,20 @@ export class OsmConnection {
}
return (
QueryParameters.GetQueryParameter(prefix + "oauth_token", undefined).data ??
window.localStorage.getItem(this._oauth_config.url + "oauth2_access_token")
window.localStorage.getItem(this.getLoginCookieName())
)
}
public setToken(token: string) {
window.localStorage.setItem(this.getLoginCookieName(), token)
}
private getLoginCookieName() {
return this._oauth_config.url + "oauth2_access_token"
}
private async loginAndroidPolyfill() {
const key = "https://www.openstreetmap.orgoauth2_access_token"
const key = this.getLoginCookieName()
if (localStorage.getItem(key)) {
// We are probably already logged in
return
@ -629,6 +645,7 @@ export class OsmConnection {
}
await this.loadUserInfo()
}
private updateAuthObject(autoLogin: boolean) {
let redirect_uri = Utils.runningFromConsole
? "https://mapcomplete.org/land.html"