Skip to content

Commit

Permalink
che-6689: fix oauth login through github in UD
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Shumilova <ashumilo@redhat.com>
  • Loading branch information
ashumilova committed Oct 12, 2017
1 parent 03ecdc8 commit 757dd97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ export class ImportGithubProjectController {
* The list of selected repositories.
*/
private selectedRepositories: Array<IGithubRepository>;
/**
* Keycloak auth service.
*/
private keycloakAuth: any;

/**
* Default constructor that is using resource
* @ngInject for Dependency injection
*/
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) {
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, keycloakAuth: any) {
this.$q = $q;
this.$mdDialog = $mdDialog;
this.$location = $location;
Expand All @@ -123,6 +130,7 @@ export class ImportGithubProjectController {
this.githubOrganizationNameResolver = githubOrganizationNameResolver;
this.resolveOrganizationName = this.githubOrganizationNameResolver.resolve;
this.addImportProjectService = addImportProjectService;
this.keycloakAuth = keycloakAuth;

this.importGithubProjectService = importGithubProjectService;
this.productName = cheBranding.getName();
Expand Down Expand Up @@ -209,6 +217,24 @@ export class ImportGithubProjectController {
return;
}

if (this.keycloakAuth.isPresent) {
this.keycloakAuth.keycloak.updateToken(5).success(() => {
let token = '&token=' + this.keycloakAuth.keycloak.token;
this.openGithubPopup(token);
}).error(() => {
this.keycloakAuth.keycloak.login();
});
} else {
this.openGithubPopup('');
}
}

/**
* Opens Github popup.
*
* @param {string} token
*/
openGithubPopup(token: string): void {
const redirectUrl = this.$location.protocol() + '://'
+ this.$location.host() + ':'
+ this.$location.port()
Expand All @@ -218,6 +244,7 @@ export class ImportGithubProjectController {
+ '?oauth_provider=github'
+ '&scope=' + ['user', 'repo', 'write:public_key'].join(',')
+ '&userId=' + this.importGithubProjectService.getCurrentUserId()
+ token
+ '&redirect_after_login='
+ redirectUrl,
{
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/github/github-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class GitHubService {
} catch (error) {
}

if (popupWindow.closed) {
if (popupWindow && popupWindow.closed) {
$interval.cancel(polling);
deferred.reject({data: 'Authorization Failed'});
}
Expand Down

0 comments on commit 757dd97

Please sign in to comment.