Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Add a warning about blocked oauth popup #815

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions extensions/eclipse-che-theia-plugin-ext/src/browser/oauth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { inject, injectable } from 'inversify';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { CheApiService } from '../common/che-protocol';
import { Emitter, Event } from '@theia/core/lib/common';
import { Emitter, Event, MessageService } from '@theia/core/lib/common';

@injectable()
export class OauthUtils {
Expand All @@ -20,6 +20,7 @@ export class OauthUtils {
private oAuthPopup: Window | undefined;
private userToken: string | undefined;
private readonly onDidReceiveToken: Event<void>;
@inject(MessageService) private readonly messageService: MessageService;
constructor(@inject(EnvVariablesServer) private readonly envVariableServer: EnvVariablesServer,
@inject(CheApiService) private readonly cheApiService: CheApiService) {
const onDidReceiveTokenEmitter = new Emitter<void>();
Expand Down Expand Up @@ -53,13 +54,20 @@ export class OauthUtils {
if (this.userToken) {
return this.userToken;
} else if (this.machineToken && this.machineToken.length > 0) {
const timer = setTimeout(() => {
this.messageService.warn('Authentication is taking too long, the oauth pop-up may be blocked by your browser, ' +
'if so, allow popup windows for the current url and restart the workspace');
}, 10000);
const popup = window.open(`${this.apiUrl.substring(0, this.apiUrl.indexOf('/api'))}/_app/oauth.html`,
'popup', 'toolbar=no, status=no, menubar=no, scrollbars=no, width=10, height=10, visible=none');
if (popup) {
this.oAuthPopup = popup;
}
return new Promise(async resolve => {
this.onDidReceiveToken(() => resolve(this.userToken));
this.onDidReceiveToken(() => {
clearTimeout(timer);
resolve(this.userToken);
});
});
}
}
Expand Down