Inkspring / website · inkspring.ai / public / desktop-connect / callback.js
| 1 | 'use strict'; |
| 2 | (() => { |
| 3 | const current = new URL(window.location.href); |
| 4 | const state = current.searchParams.get('state') || ''; |
| 5 | const provider = state.match(/^(x|instagram|linkedin)\.[A-Za-z0-9_-]{40,100}$/)?.[1]; |
| 6 | const code = current.searchParams.get('code'); |
| 7 | const error = current.searchParams.get('error'); |
| 8 | // Remove the authorization code from browser history before opening the application. |
| 9 | window.history.replaceState(null, '', window.location.pathname); |
| 10 | if (!provider || ((!code || code.length > 8000) && !error) || (error && error.length > 200)) { |
| 11 | document.getElementById('message').textContent = 'This sign-in return is missing or invalid. Open Inkspring and start connecting the account again.'; |
| 12 | return; |
| 13 | } |
| 14 | const target = new URL(`inkspring://oauth/${provider}`); |
| 15 | target.searchParams.set('state', state); |
| 16 | if (error) target.searchParams.set('error', error); else target.searchParams.set('code', code); |
| 17 | const link = document.getElementById('return'); |
| 18 | link.href = target.href; |
| 19 | link.hidden = false; |
| 20 | document.getElementById('message').textContent = error ? 'Sign-in was canceled. Return to Inkspring to continue.' : 'Your browser can now return the sign-in result to Inkspring. Select the button and allow your browser to open the installed app.'; |
| 21 | })(); |