Skip to content

Commit 9541526

Browse files
committed
fixup! Apply OpenShift OAuth provider
1 parent 4d2b3f5 commit 9541526

4 files changed

Lines changed: 63 additions & 29 deletions

File tree

assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ che.oauth.github.authuri= https://github.com/login/oauth/authorize
161161
che.oauth.github.tokenuri= https://github.com/login/oauth/access_token
162162
che.oauth.github.redirecturis= http://localhost:${CHE_PORT}/api/oauth/callback
163163

164-
# You can setup GitHub OAuth to automate authentication to remote repositories.
165-
# You need to first register this application with OpenShift OAuth.
166164
che.oauth.openshift.clientid=NULL
167165
che.oauth.openshift.clientsecret=NULL
168166
che.oauth.openshift.endpoint= NULL

assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/multiuser.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@ che.keycloak.username_claim=NULL
161161
# If set to "embedded", then the service work as a wrapper to Che's OAuthAuthenticator ( as in Single User mode).
162162
# If set to "delegated", then the service will use Keycloak IdentityProvider mechanism.
163163
# Runtime Exception wii be thrown, in case if this property is not set properly.
164-
che.oauth.service_mode=delegated
164+
che.oauth.service_mode=embedded

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

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ImportGithubProjectService, LoadingState } from './import-github-projec
1616
import { ProjectSource } from '../../project-source.enum';
1717
import { IGithubRepository } from './github-repository-interface';
1818
import { AddImportProjectService } from '../add-import-project.service';
19+
import { CheNotification } from '../../../../../../../components/notification/che-notification.factory';
1920

2021
/**
2122
* This class is handling the controller for the GitHub part
@@ -25,9 +26,23 @@ import { AddImportProjectService } from '../add-import-project.service';
2526
*/
2627
export class ImportGithubProjectController {
2728

28-
static $inject = ['$q', '$mdDialog', '$location', '$browser', '$scope', 'githubPopup', 'cheBranding', 'githubOrganizationNameResolver',
29-
'importGithubProjectService', 'cheListHelperFactory', 'addImportProjectService', 'keycloakAuth'];
29+
static $inject = [
30+
'$browser',
31+
'$location',
32+
'$mdDialog',
33+
'$q',
34+
'$scope',
35+
'addImportProjectService',
36+
'cheBranding',
37+
'cheListHelperFactory',
38+
'cheNotification',
39+
'githubOrganizationNameResolver',
40+
'githubPopup',
41+
'importGithubProjectService',
42+
'keycloakAuth',
43+
];
3044

45+
private cheNotification: CheNotification
3146
/**
3247
* Promises service.
3348
*/
@@ -121,21 +136,33 @@ export class ImportGithubProjectController {
121136
/**
122137
* Default constructor that is using resource
123138
*/
124-
constructor($q: ng.IQService, $mdDialog: ng.material.IDialogService, $location: ng.ILocationService,
125-
$browser: any, $scope: ng.IScope, githubPopup: any, cheBranding: CheBranding,
126-
githubOrganizationNameResolver: any, importGithubProjectService: ImportGithubProjectService,
127-
cheListHelperFactory: che.widget.ICheListHelperFactory, addImportProjectService: AddImportProjectService, keycloakAuth: any) {
128-
this.$q = $q;
129-
this.$mdDialog = $mdDialog;
130-
this.$location = $location;
139+
constructor(
140+
$browser: any,
141+
$location: ng.ILocationService,
142+
$mdDialog: ng.material.IDialogService,
143+
$q: ng.IQService,
144+
$scope: ng.IScope,
145+
addImportProjectService: AddImportProjectService,
146+
cheBranding: CheBranding,
147+
cheListHelperFactory: che.widget.ICheListHelperFactory,
148+
cheNotification: CheNotification,
149+
githubOrganizationNameResolver: any,
150+
githubPopup: any,
151+
importGithubProjectService: ImportGithubProjectService,
152+
keycloakAuth: any,
153+
) {
131154
this.$browser = $browser;
132-
this.githubPopup = githubPopup;
155+
this.$location = $location;
156+
this.$mdDialog = $mdDialog;
157+
this.$q = $q;
158+
this.addImportProjectService = addImportProjectService;
133159
this.cheBranding = cheBranding;
160+
this.cheNotification = cheNotification;
134161
this.githubOrganizationNameResolver = githubOrganizationNameResolver;
135-
this.resolveOrganizationName = this.githubOrganizationNameResolver.resolve;
136-
this.addImportProjectService = addImportProjectService;
137-
this.keycloakAuth = keycloakAuth;
162+
this.githubPopup = githubPopup;
138163
this.importGithubProjectService = importGithubProjectService;
164+
this.keycloakAuth = keycloakAuth;
165+
this.resolveOrganizationName = this.githubOrganizationNameResolver.resolve;
139166

140167
this.productName = cheBranding.getName();
141168
this.loadingState = LoadingState;
@@ -232,25 +259,31 @@ export class ImportGithubProjectController {
232259
return;
233260
}
234261

235-
if (this.keycloakAuth.isPresent) {
236-
this.keycloakAuth.keycloak.updateToken(5).success(() => {
237-
let token = '&token=' + this.keycloakAuth.keycloak.token;
238-
this.openGithubPopup(token);
239-
}).error(() => {
240-
window.sessionStorage.setItem('oidcDashboardRedirectUrl', location.href);
241-
this.keycloakAuth.keycloak.login();
242-
});
243-
} else {
244-
this.openGithubPopup('');
245-
}
262+
this.importGithubProjectService.getOrFetchUserId().then((userId: string) => {
263+
if (this.keycloakAuth.isPresent) {
264+
this.keycloakAuth.keycloak.updateToken(5).success(() => {
265+
let token = '&token=' + this.keycloakAuth.keycloak.token;
266+
this.openGithubPopup(userId, token);
267+
}).error(() => {
268+
window.sessionStorage.setItem('oidcDashboardRedirectUrl', location.href);
269+
this.keycloakAuth.keycloak.login();
270+
});
271+
} else {
272+
this.openGithubPopup(userId, '');
273+
}
274+
}).catch((error: any) => {
275+
this.cheNotification.showError('Authentication to GitHub failed.');
276+
console.error('Authentication to GitHub failed:', error);
277+
});
246278
}
247279

248280
/**
249281
* Opens Github popup.
250282
*
283+
* @param {string} userId
251284
* @param {string} token
252285
*/
253-
openGithubPopup(token: string): void {
286+
openGithubPopup(userId: string, token: string): void {
254287
// given URL http://example.com - returns port => 80 (or 443 with https), which causes wrong redirect URL value:
255288
let port = (this.$location.port() === 80 || this.$location.port() === 443) ? '' : ':' + this.$location.port();
256289
const redirectUrl = this.$location.protocol() + '://'
@@ -261,7 +294,7 @@ export class ImportGithubProjectController {
261294
let link = '/api/oauth/authenticate'
262295
+ '?oauth_provider=github'
263296
+ '&scope=' + ['user', 'repo', 'write:public_key'].join(',')
264-
+ '&userId=' + this.importGithubProjectService.getCurrentUserId()
297+
+ '&userId=' + userId
265298
+ token
266299
+ '&redirect_after_login='
267300
+ redirectUrl;

multiuser/machine-auth/che-multiuser-machine-authentication/src/main/java/org/eclipse/che/multiuser/machine/authentication/server/MachineAuthModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ protected void configure() {
8282
machineAuthenticatedResources
8383
.addBinding()
8484
.toInstance(new MachineAuthenticatedResource("/activity", "active"));
85+
machineAuthenticatedResources
86+
.addBinding()
87+
.toInstance(new MachineAuthenticatedResource("oauth", "token"));
8588

8689
machineAuthenticatedResources
8790
.addBinding()

0 commit comments

Comments
 (0)