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

Commit

Permalink
Add a warning about blocked oauth popup (#815)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig authored Jul 27, 2020
1 parent 537ad3a commit 2f11124
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 2f11124

Please sign in to comment.