This reverts commit b53427b910.
This commit is contained in:
@@ -40,7 +40,7 @@ export default () => {
|
|||||||
centered
|
centered
|
||||||
closable={false}
|
closable={false}
|
||||||
title={null}
|
title={null}
|
||||||
open={open}
|
visible={open}
|
||||||
footer={null}
|
footer={null}
|
||||||
destroyOnClose={true}
|
destroyOnClose={true}
|
||||||
width={ModalManager.getPosition()?.size?.width || '700px'}
|
width={ModalManager.getPosition()?.size?.width || '700px'}
|
||||||
|
|||||||
@@ -48,16 +48,11 @@ class AuthService {
|
|||||||
return this.provider;
|
return this.provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.debug(`Configured '${accountType}' auth provider`)
|
|
||||||
const config = InitService.server_infos?.configuration?.accounts[accountType];
|
const config = InitService.server_infos?.configuration?.accounts[accountType];
|
||||||
|
|
||||||
this.logger.debug("Using configuration ...");
|
|
||||||
this.logger.debug(config);
|
|
||||||
|
|
||||||
if (Globals.environment.env_dev_auth) accountType = Globals.environment.env_dev_auth;
|
if (Globals.environment.env_dev_auth) accountType = Globals.environment.env_dev_auth;
|
||||||
|
|
||||||
if (accountType === 'remote') {
|
if (accountType === 'remote') {
|
||||||
this.logger.debug('Using remote OIDC auth provider');
|
|
||||||
this.provider = new OIDCAuthProviderService(config as ConsoleConfiguration);
|
this.provider = new OIDCAuthProviderService(config as ConsoleConfiguration);
|
||||||
} else if (accountType === 'internal') {
|
} else if (accountType === 'internal') {
|
||||||
this.provider = new InternalAuthProviderService(config as InternalConfiguration);
|
this.provider = new InternalAuthProviderService(config as InternalConfiguration);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import { getAsFrontUrl } from '@features/global/utils/URLUtils';
|
|||||||
import { TdriveService } from '../../../global/framework/registry-decorator-service';
|
import { TdriveService } from '../../../global/framework/registry-decorator-service';
|
||||||
import EnvironmentService from '../../../global/framework/environment-service';
|
import EnvironmentService from '../../../global/framework/environment-service';
|
||||||
import { AuthProvider, InitParameters } from '../auth-provider';
|
import { AuthProvider, InitParameters } from '../auth-provider';
|
||||||
|
import ConsoleService from '@features/console/services/console-service';
|
||||||
|
import jwtStorageService, { JWTDataType } from '@features/auth/jwt-storage-service';
|
||||||
import LocalStorage from '@features/global/framework/local-storage-service';
|
import LocalStorage from '@features/global/framework/local-storage-service';
|
||||||
|
|
||||||
const OIDC_CALLBACK_URL = '/oidccallback';
|
const OIDC_CALLBACK_URL = '/oidccallback';
|
||||||
@@ -53,11 +55,11 @@ export default class OIDCAuthProviderService
|
|||||||
scope: 'openid profile email address phone offline_access',
|
scope: 'openid profile email address phone offline_access',
|
||||||
post_logout_redirect_uri: getAsFrontUrl(OIDC_SIGNOUT_URL),
|
post_logout_redirect_uri: getAsFrontUrl(OIDC_SIGNOUT_URL),
|
||||||
silent_redirect_uri: getAsFrontUrl(OIDC_SILENT_URL),
|
silent_redirect_uri: getAsFrontUrl(OIDC_SILENT_URL),
|
||||||
automaticSilentRenew: false,
|
automaticSilentRenew: true,
|
||||||
loadUserInfo: true,
|
loadUserInfo: true,
|
||||||
accessTokenExpiringNotificationTime: 10,
|
accessTokenExpiringNotificationTime: 10,
|
||||||
filterProtocolClaims: true,
|
filterProtocolClaims: true,
|
||||||
monitorSession: true,
|
monitorSession: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// For logout if signout or logout endpoint called
|
// For logout if signout or logout endpoint called
|
||||||
@@ -67,14 +69,6 @@ export default class OIDCAuthProviderService
|
|||||||
this.signOut();
|
this.signOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.userManager.events.addUserSignedIn(() => {
|
|
||||||
this.logger.debug('User Signed In:');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.userManager.events.addUserSignedOut(() => {
|
|
||||||
this.logger.debug('User Signed Out:');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.userManager.events.addUserLoaded((user: any, ...args) => {
|
this.userManager.events.addUserLoaded((user: any, ...args) => {
|
||||||
this.logger.debug('New User Loaded:', user, args);
|
this.logger.debug('New User Loaded:', user, args);
|
||||||
this.logger.debug('Acess_token: ', user.access_token);
|
this.logger.debug('Acess_token: ', user.access_token);
|
||||||
@@ -100,7 +94,7 @@ export default class OIDCAuthProviderService
|
|||||||
this.logger.info('Signin');
|
this.logger.info('Signin');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.userManager?.signinRedirectCallback();
|
await this.userManager!.signinRedirectCallback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Not connected, connect through SSO');
|
console.log('Not connected, connect through SSO');
|
||||||
}
|
}
|
||||||
@@ -108,10 +102,22 @@ export default class OIDCAuthProviderService
|
|||||||
const user = await this.userManager?.getUser();
|
const user = await this.userManager?.getUser();
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
this.getJWTFromOidcToken(user, (err, jwt) => {
|
||||||
|
if (err) {
|
||||||
|
this.logger.error(
|
||||||
|
'OIDC user loaded listener, error while getting the JWT from OIDC token',
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
this.signinRedirect();
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.initialized) {
|
if (!this.initialized) {
|
||||||
this.onInitialized();
|
this.onInitialized();
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
|
} else {
|
||||||
|
jwt && this.params!.onNewToken(jwt);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.userManager?.signinRedirect();
|
this.userManager?.signinRedirect();
|
||||||
}
|
}
|
||||||
@@ -142,6 +148,45 @@ export default class OIDCAuthProviderService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to get a new JWT token from the OIDC one:
|
||||||
|
* Call the backend with the OIDC token, it will use it to get a new token from console
|
||||||
|
*/
|
||||||
|
private async getJWTFromOidcToken(
|
||||||
|
user: Oidc.User,
|
||||||
|
callback: (err?: Error, accessToken?: JWTDataType) => void,
|
||||||
|
): Promise<void> {
|
||||||
|
if (!user) {
|
||||||
|
this.logger.info('getJWTFromOidcToken, Cannot getJWTFromOidcToken with a null user');
|
||||||
|
callback(new Error('Cannot getJWTFromOidcToken with a null user'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.expired) {
|
||||||
|
// TODO: try to get a new token from refresh one before asking for a JWT token
|
||||||
|
this.logger.info('getJWTFromOidcToken, user expired');
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleService.getNewAccessToken(
|
||||||
|
{ id_token: user.id_token, access_token: user.access_token },
|
||||||
|
callback,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
signinRedirect() {
|
||||||
|
if (document.location.href.indexOf('/login') === -1) {
|
||||||
|
//Save requested URL for after redirect / sign-in
|
||||||
|
LocalStorage.setItem('requested_url', {
|
||||||
|
url: document.location.href,
|
||||||
|
time: new Date().getTime(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
jwtStorageService.clear();
|
||||||
|
|
||||||
|
if (this.userManager) this.userManager.signinRedirect();
|
||||||
|
}
|
||||||
|
|
||||||
onInitialized() {
|
onInitialized() {
|
||||||
//If user requested an url in the last 10 minutes, we open it
|
//If user requested an url in the last 10 minutes, we open it
|
||||||
const ref = LocalStorage.getItem('requested_url') as { url: string; time: number };
|
const ref = LocalStorage.getItem('requested_url') as { url: string; time: number };
|
||||||
|
|||||||
Reference in New Issue
Block a user