Improve Oauth2 Dialog

This commit is contained in:
George Kalampokis 2022-04-15 14:01:46 +03:00
parent 6542841c6c
commit 2c94cfa130
6 changed files with 18 additions and 158 deletions

View File

@ -6,7 +6,6 @@ import { AuthService } from '@app/core/services/auth/auth.service';
import { ConfigurableProvidersService } from '@app/ui/auth/login/utilities/configurableProviders.service'; import { ConfigurableProvidersService } from '@app/ui/auth/login/utilities/configurableProviders.service';
import { LoginService } from '@app/ui/auth/login/utilities/login.service'; import { LoginService } from '@app/ui/auth/login/utilities/login.service';
import { BaseComponent } from '@common/base/base.component'; import { BaseComponent } from '@common/base/base.component';
import { environment } from 'environments/environment';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
import { MergeLoginService } from './utilities/merge-login.service'; import { MergeLoginService } from './utilities/merge-login.service';
@ -251,11 +250,11 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
client_id: this.configurationService.loginProviders.googleConfiguration.clientId, client_id: this.configurationService.loginProviders.googleConfiguration.clientId,
scope: 'profile email' scope: 'profile email'
}); });
this.attachGoogleSignΙn(document.getElementById('googleSignInButton')); this.attachGoogleSignIn(document.getElementById('googleSignInButton'));
}); });
} }
public attachGoogleSignΙn(element) { public attachGoogleSignIn(element) {
if (!element) { return; } if (!element) { return; }
this.auth2.attachClickHandler(element, {}, this.auth2.attachClickHandler(element, {},
(googleUser) => { (googleUser) => {

View File

@ -33,15 +33,13 @@ export class Oauth2DialogComponent extends BaseComponent implements OnInit{
} }
private sendCode(params: Params) { private sendCode(params: Params) {
if (params['code']) { const oauthObject = {
localStorage.setItem('oauthCode', params['code']); oauthCode: params['code'] ? params['code'] : undefined,
} oauthState: params['state'] ? params['state'] : undefined,
if (params['state']) { oauthToken: params['oauth_token'] ? params['oath_token'] : undefined,
localStorage.setItem('oauthState', params['state']); oauthVerifier: params['oauth_verifier'] ? params['oauth_verifier'] : undefined
} };
if (params['oauth_token'] && params['oauth_verifier']) { localStorage.setItem('arglogRes', JSON.stringify({response: { date: new Date(), data: oauthObject }}));
localStorage.setItem('oauthObject', JSON.stringify({oauth_token: params['oauth_token'], oauth_verifier: params['oauth_verifier']}));
}
window.close(); window.close();
} }

View File

@ -14,7 +14,7 @@ export class Oauth2DialogService extends BaseService{
super(); super();
} }
public registerCode(code: string) { public registerCode(code: any) {
this.code.next(code); this.code.next(code);
} }
@ -22,26 +22,14 @@ export class Oauth2DialogService extends BaseService{
const windows = window.open(this.configurationService.app + 'oauth2?url=' + encodeURIComponent(url) ,'', `height=500px,width=500px,top=${(window.screen.height / 2) - 200}px,left=${(window.screen.width / 2) - 200}px`); const windows = window.open(this.configurationService.app + 'oauth2?url=' + encodeURIComponent(url) ,'', `height=500px,width=500px,top=${(window.screen.height / 2) - 200}px,left=${(window.screen.width / 2) - 200}px`);
const sub = interval(300).pipe(takeUntil(this._destroyed)).subscribe(() => { const sub = interval(300).pipe(takeUntil(this._destroyed)).subscribe(() => {
if (windows.closed) { if (windows.closed) {
let oauthCode; if (localStorage.getItem('arglogRes')) {
let oauthState; const oauthResponse = JSON.parse(localStorage.getItem('arglogRes'));
let oauthToken; localStorage.removeItem('arglogRes');
let oauthVerifier; const oauthObject = oauthResponse.response.data;
if (localStorage.getItem('oauthCode')) { this.code.next(oauthObject);
oauthCode = localStorage.getItem('oauthCode');
localStorage.removeItem('oauthCode');
}
if (localStorage.getItem('oauthState')) {
oauthState = localStorage.getItem('oauthState');
localStorage.removeItem('oauthState');
}
if (localStorage.getItem('oauthObject')) {
const oauthObject = JSON.parse(localStorage.getItem('oauthObject'));
localStorage.removeItem('oauthObject');
oauthToken = oauthObject.oauth_token;
oauthVerifier = oauthObject.oauth_verifier;
}
this.code.next({oauthCode: oauthCode, oauthState: oauthState, oauthToken: oauthToken, oauthVerifier: oauthVerifier});
this.code.next(undefined); this.code.next(undefined);
}
sub.unsubscribe(); sub.unsubscribe();
} }
}); });

View File

@ -1,40 +0,0 @@
export const environment = {
production: true,
Server: 'https://devel.opendmp.eu/srv/api/',
App: 'https://devel.opendmp.eu/',
HelpService: {
Enabled: false,
Url: 'https://devel.opendmp.eu/content-service/',
},
defaultCulture: 'en-US',
loginProviders: {
enabled: [1, 2, 3, 4, 5, 6],
facebookConfiguration: { clientId: '' },
googleConfiguration: { clientId: '' },
linkedInConfiguration: {
clientId: '',
oauthUrl: 'https://www.linkedin.com/oauth/v2/authorization',
redirectUri: 'http://localhost:4200/login/linkedin',
state: ''
},
twitterConfiguration: {
clientId: '',
oauthUrl: 'https://api.twitter.com/oauth/authenticate'
},
b2accessConfiguration: {
clientId: '',
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
redirectUri: 'http://opendmp.eu/api/oauth/authorized/b2access',
state: ''
},
orcidConfiguration: {
clientId: 'APP-766DI5LP8T75FC4R',
oauthUrl: 'https://sandbox.orcid.org/oauth/authorize',
redirectUri: 'http://opendmp.eu/api/oauth/authorized/orcid'
}
},
logging: {
enabled: false,
logLevels: ["debug", "info", "warning", "error"]
},
};

View File

@ -1,40 +0,0 @@
export const environment = {
production: true,
Server: 'https://devel.opendmp.eu/srv/api/',
App: 'https://devel.opendmp.eu/',
HelpService: {
Enabled: false,
Url: 'https://devel.opendmp.eu/content-service/',
},
defaultCulture: 'en-US',
loginProviders: {
enabled: [1, 2, 3, 4, 5, 6],
facebookConfiguration: { clientId: '' },
googleConfiguration: { clientId: '596924546661-83nhl986pnrpug5h624i5kptuao03dcd.apps.googleusercontent.com' },
linkedInConfiguration: {
clientId: '',
oauthUrl: 'https://www.linkedin.com/oauth/v2/authorization',
redirectUri: 'https://devel.opendmp.eu/login/linkedin',
state: ''
},
twitterConfiguration: {
clientId: '',
oauthUrl: 'https://api.twitter.com/oauth/authenticate'
},
b2accessConfiguration: {
clientId: '',
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
redirectUri: 'http://devel.opendmp.eu/api/oauth/authorized/b2access',
state: ''
},
orcidConfiguration: {
clientId: '',
oauthUrl: 'https://sandbox.orcid.org/oauth/authorize',
redirectUri: 'http://opendmp.eu/api/oauth/authorized/orcid'
}
},
logging: {
enabled: false,
logLevels: ["debug", "info", "warning", "error"]
},
};

View File

@ -1,48 +1,3 @@
export const environment = { export const environment = {
production: false, production: false
Server: 'http://localhost:8080/api/',
App: 'http://localhost:4200/',
HelpService: {
Enabled: false,
Url: 'localhost:5000/',
},
defaultCulture: 'en-US',
loginProviders: {
enabled: [1, 2, 3, 4, 5, 6, 7, 8],
facebookConfiguration: { clientId: '' },
googleConfiguration: { clientId: '' },
linkedInConfiguration: {
clientId: '',
oauthUrl: 'https://www.linkedin.com/oauth/v2/authorization',
redirectUri: 'http://localhost:4200/login/linkedin',
state: '987654321'
},
twitterConfiguration: {
clientId: '',
oauthUrl: 'https://api.twitter.com/oauth/authenticate'
},
b2accessConfiguration: {
clientId: '',
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
redirectUri: 'http://localhost:4200/api/oauth/authorized/b2access',
state: ''
},
orcidConfiguration: {
clientId: 'APP-766DI5LP8T75FC4R',
oauthUrl: 'https://orcid.org/oauth/authorize',
redirectUri: 'http://localhost:4200/login/external/orcid'
},
openAireConfiguration: {
clientId: '',
oauthUrl: '',
redirectUri: '',
state: '987654321'
}
},
logging: {
enabled: true,
logLevels: ["debug", "info", "warning", "error"]
},
lockInterval: 60000,
guideAssets: "assets/images/guide"
}; };