resolve_flexible_tokens.html (1448B)
1 <!DOCTYPE html> 2 <script> 3 async function doResolve() { 4 let urlParams = new URLSearchParams(document.location.search); 5 let options = {}; 6 7 const paramsStr = urlParams.get("params"); 8 const params = JSON.parse(decodeURIComponent(paramsStr)); 9 10 // Extract values from params 11 const accountId = params.accountId; 12 const tokenType = params.tokenType; 13 const tokenValue = params.tokenValue; 14 15 // Set accountId option if present 16 if (accountId) { 17 options.accountId = accountId; 18 } 19 20 let token; 21 22 // Process token based on tokenType 23 switch (tokenType) { 24 case "number": 25 token = parseFloat(tokenValue); 26 break; 27 28 case "boolean": 29 token = tokenValue === true || tokenValue === "true"; 30 break; 31 32 case "null": 33 token = null; 34 break; 35 36 case "object": 37 if (typeof tokenValue === "object") { 38 token = tokenValue; 39 } else { 40 try { 41 token = JSON.parse(tokenValue); 42 } catch (e) { 43 token = { value: tokenValue }; 44 } 45 } 46 break; 47 48 case "array": 49 if (Array.isArray(tokenValue)) { 50 token = tokenValue; 51 } else { 52 try { 53 token = JSON.parse(tokenValue); 54 } catch (e) { 55 token = [tokenValue]; 56 } 57 } 58 break; 59 60 case "string": 61 default: 62 token = String(tokenValue); 63 break; 64 } 65 66 IdentityProvider.resolve(token, options); 67 } 68 69 window.onload = doResolve; 70 </script>