| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2025-02-13 22:07:45 +01:00
										 |  |  | import { QueryParameters } from "../src/Logic/Web/QueryParameters" | 
					
						
							| 
									
										
										
										
											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
										 |  |  | const connection = new OsmConnection() | 
					
						
							|  |  |  | connection.finishLogin(async () => { | 
					
						
							|  |  |  |     let token: string = undefined | 
					
						
							|  |  |  |     let attempt = 0 | 
					
						
							|  |  |  |     do { | 
					
						
							|  |  |  |         await Utils.waitFor(500) | 
					
						
							|  |  |  |         token = connection.getToken() | 
					
						
							| 
									
										
										
										
											2025-02-10 02:04:58 +01:00
										 |  |  |         tokenSrc.set("Trying to get token (" + attempt + ")") | 
					
						
							| 
									
										
										
										
											2025-02-05 13:20:51 +01:00
										 |  |  |         attempt++ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const dbg = [] | 
					
						
							| 
									
										
										
										
											2025-02-10 02:04:58 +01:00
										 |  |  |         Object.keys(localStorage).forEach((key) => { | 
					
						
							|  |  |  |             dbg.push(`${key} - ${localStorage.getItem(key)}`) | 
					
						
							| 
									
										
										
										
											2025-02-05 13:20:51 +01:00
										 |  |  |         }) | 
					
						
							|  |  |  |         debug.set(dbg) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-10 02:04:58 +01:00
										 |  |  |         if (attempt > 10) { | 
					
						
							| 
									
										
										
										
											2025-02-13 22:07:45 +01:00
										 |  |  |             QueryParameters.ClearAll() | 
					
						
							| 
									
										
										
										
											2025-02-05 18:21:50 +01:00
										 |  |  |             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
										 |  |  | }) |