Silent renew without refresh tokens

This commit is contained in:
2021-03-22 19:32:27 +01:00
parent de0ae01fb2
commit e547551fde
3 changed files with 24 additions and 34 deletions

View File

@@ -20,7 +20,7 @@ export function configureAuth(oidcConfigService: OidcConfigService): () => Promi
tokenRefreshInSeconds: 20,
ignoreNonceAfterRefresh: true, // El refresh token está fallando si no se ignora el Nonce
secureRoutes: [TRAVEL_API_URL, USER_API_URL],
// storage: localStorage,
storage: localStorage,
logLevel: LogLevel.Warn
});
}

View File

@@ -53,15 +53,16 @@ export class AuthService {
this.userSubject.next(User.fromClaims(claims));
});
if ((sessionStorage.getItem('chatLoginInProcess') === 'true') || chatLoginToken) {
sessionStorage.removeItem('chatLoginInProcess');
return this.oidcSecurityService.checkAuth().toPromise().then(async (auth) => {
console.log('AUTH INITIALIZED result=', auth);
if (auth) {
if (sessionStorage.getItem('chatLoginInProcess') === 'true') {
sessionStorage.removeItem('chatLoginInProcess');
return this.oidcSecurityService.checkAuth().toPromise().then((auth) => {
console.log('AUTH INITIALIZED result=', auth);
if (auth) {
if (chatLoginToken) {
console.log('chatLoginToken=' + chatLoginToken);
this.chatService.login(chatLoginToken);
await this.chatService.login(chatLoginToken);
}
else {
console.error('CHAT LOGIN TOKEN NOT RECEIVED');
@@ -72,23 +73,15 @@ export class AuthService {
return AuthState.Logged;
}
return AuthState.NotLogged;
});
}
else {
return this.oidcSecurityService.checkAuthIncludingServer().toPromise().then((auth) => {
console.log('AUTH INITIALIZED result=', auth);
if (auth) {
else {
console.log('GO TO SSO LOGIN');
sessionStorage.setItem('chatLoginInProcess', 'true');
this.chatService.goToSsoLogin();
return AuthState.ChatLoggingInProcess;
}
}
return AuthState.NotLogged;
});
}
return AuthState.NotLogged;
});
}
}

View File

@@ -14,27 +14,24 @@ export class ChatService {
window.location.href = 'http://synapse:8008/_matrix/client/r0/login/sso/redirect?redirectUrl=http://localhost:4200/';
}
login(loginToken: string): Promise<void | object> {
return this.http.post<object>(
async login(loginToken: string): Promise<void> {
const res = await this.http.post<object>(
'http://synapse:8008/_matrix/client/r0/login',
{
initial_device_display_name: 'Okupa mi coche',
token: loginToken,
type: 'm.login.token'
}
).toPromise().then(res => {
console.log('LOGGED TO CHAT');
console.log(res);
const client = matrix.createClient({
baseUrl: "http://localhost:8008",
accessToken: res['access_token'],
userId: res['user_id']
});
client.publicRooms(function (err, data) {
console.log("Public Rooms: %s", JSON.stringify(data));
});
).toPromise();
console.log('LOGGED TO CHAT');
console.log(res);
const client = matrix.createClient({
baseUrl: 'http://localhost:8008',
accessToken: res['access_token'],
userId: res['user_id']
});
client.publicRooms((err: any, data: any) => {
console.log('Public Rooms: %s', JSON.stringify(data));
});
}
}