@@ -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 {
0 commit comments