()
| 30 | |
| 31 | // https://docs.gitlab.com/ee/api/oauth2.html#authorization-code-flow |
| 32 | export const ConnectToGitLab = async () => { |
| 33 | const STATE = createRandomString(32); |
| 34 | const opener = window.open(createAuthorizeUrl(STATE), '_blank', OPEN_WINDOW_FEATURES); |
| 35 | |
| 36 | return new Promise((resolve) => { |
| 37 | const handleAuthMessage = (event: MessageEvent) => { |
| 38 | // Note that though the browser block opening window and popup a tip, |
| 39 | // the user can be still open it from the tip. In this case, the `opener` |
| 40 | // is null, and we should still process the authorizing message |
| 41 | const isValidOpener = !!(opener && event.source === opener); |
| 42 | const isValidOrigin = event.origin === AUTH_PAGE_ORIGIN; |
| 43 | const isValidResponse = event.data ? event.data.type === 'authorizing' : false; |
| 44 | if (!isValidOpener || !isValidOrigin || !isValidResponse) { |
| 45 | return; |
| 46 | } |
| 47 | window.removeEventListener('message', handleAuthMessage); |
| 48 | resolve(event.data?.payload); |
| 49 | }; |
| 50 | |
| 51 | window.addEventListener('message', handleAuthMessage); |
| 52 | // if there isn't any message from opener window in 300s, remove the message handler |
| 53 | timeout(300 * 1000).then(() => { |
| 54 | window.removeEventListener('message', handleAuthMessage); |
| 55 | resolve({ error: 'authorizing_timeout', error_description: 'Authorizing timeout' }); |
| 56 | }); |
| 57 | }); |
| 58 | }; |
nothing calls this directly
no test coverage detected