Skip to content

Commit 757dd97

Browse files
committed
che-6689: fix oauth login through github in UD
Signed-off-by: Anna Shumilova <ashumilo@redhat.com>
1 parent 03ecdc8 commit 757dd97

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

dashboard/src/app/workspaces/create-workspace/project-source-selector/add-import-project/import-github-project/import-github-project.controller.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,19 @@ export class ImportGithubProjectController {
108108
* The list of selected repositories.
109109
*/
110110
private selectedRepositories: Array<IGithubRepository>;
111+
/**
112+
* Keycloak auth service.
113+
*/
114+
private keycloakAuth: any;
111115

112116
/**
113117
* Default constructor that is using resource
114118
* @ngInject for Dependency injection
115119
*/
116-
constructor ($q: ng.IQService, $mdDialog: ng.material.IDialogService, $location: ng.ILocationService, $browser: ng.IBrowserService, $scope: ng.IScope, githubPopup: any, cheBranding: CheBranding, githubOrganizationNameResolver: any, importGithubProjectService: ImportGithubProjectService, cheListHelperFactory: che.widget.ICheListHelperFactory, addImportProjectService: AddImportProjectService) {
120+
constructor ($q: ng.IQService, $mdDialog: ng.material.IDialogService, $location: ng.ILocationService,
121+
$browser: ng.IBrowserService, $scope: ng.IScope, githubPopup: any, cheBranding: CheBranding,
122+
githubOrganizationNameResolver: any, importGithubProjectService: ImportGithubProjectService,
123+
cheListHelperFactory: che.widget.ICheListHelperFactory, addImportProjectService: AddImportProjectService, keycloakAuth: any) {
117124
this.$q = $q;
118125
this.$mdDialog = $mdDialog;
119126
this.$location = $location;
@@ -123,6 +130,7 @@ export class ImportGithubProjectController {
123130
this.githubOrganizationNameResolver = githubOrganizationNameResolver;
124131
this.resolveOrganizationName = this.githubOrganizationNameResolver.resolve;
125132
this.addImportProjectService = addImportProjectService;
133+
this.keycloakAuth = keycloakAuth;
126134

127135
this.importGithubProjectService = importGithubProjectService;
128136
this.productName = cheBranding.getName();
@@ -209,6 +217,24 @@ export class ImportGithubProjectController {
209217
return;
210218
}
211219

220+
if (this.keycloakAuth.isPresent) {
221+
this.keycloakAuth.keycloak.updateToken(5).success(() => {
222+
let token = '&token=' + this.keycloakAuth.keycloak.token;
223+
this.openGithubPopup(token);
224+
}).error(() => {
225+
this.keycloakAuth.keycloak.login();
226+
});
227+
} else {
228+
this.openGithubPopup('');
229+
}
230+
}
231+
232+
/**
233+
* Opens Github popup.
234+
*
235+
* @param {string} token
236+
*/
237+
openGithubPopup(token: string): void {
212238
const redirectUrl = this.$location.protocol() + '://'
213239
+ this.$location.host() + ':'
214240
+ this.$location.port()
@@ -218,6 +244,7 @@ export class ImportGithubProjectController {
218244
+ '?oauth_provider=github'
219245
+ '&scope=' + ['user', 'repo', 'write:public_key'].join(',')
220246
+ '&userId=' + this.importGithubProjectService.getCurrentUserId()
247+
+ token
221248
+ '&redirect_after_login='
222249
+ redirectUrl,
223250
{

dashboard/src/components/github/github-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class GitHubService {
8282
} catch (error) {
8383
}
8484

85-
if (popupWindow.closed) {
85+
if (popupWindow && popupWindow.closed) {
8686
$interval.cancel(polling);
8787
deferred.reject({data: 'Authorization Failed'});
8888
}

0 commit comments

Comments
 (0)