Refresh tokens corregidos
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export const API_BASE_URL = 'http://localhost:8080/api';
|
||||
export const API_BASE_URL = 'http://localhost:8081/api';
|
||||
|
||||
const PUBLIC_API_RELATIVE_PATH = '/public';
|
||||
export const PUBLIC_API_URL = API_BASE_URL + PUBLIC_API_RELATIVE_PATH;
|
||||
|
||||
@@ -6,7 +6,8 @@ import { TRAVEL_API_URL, USER_API_URL } from '../app.config';
|
||||
export function configureAuth(oidcConfigService: OidcConfigService): () => Promise<any> {
|
||||
return () =>
|
||||
oidcConfigService.withConfig({
|
||||
stsServer: 'https://auth.fosil.eu/auth/realms/test',
|
||||
stsServer: 'http://localhost:8080/auth/realms/okupamicoche',
|
||||
// stsServer: 'https://auth.fosil.eu/auth/realms/test',
|
||||
redirectUrl: window.location.origin,
|
||||
postLogoutRedirectUri: window.location.origin,
|
||||
clientId: 'okupamicoche-frontend-angular',
|
||||
@@ -15,7 +16,10 @@ export function configureAuth(oidcConfigService: OidcConfigService): () => Promi
|
||||
silentRenew: true,
|
||||
useRefreshToken: true,
|
||||
renewTimeBeforeTokenExpiresInSeconds: 30,
|
||||
tokenRefreshInSeconds: 20,
|
||||
ignoreNonceAfterRefresh: true, // El refresh token está fallando si no se ignora el Nonce
|
||||
secureRoutes: [TRAVEL_API_URL, USER_API_URL],
|
||||
logLevel: 1
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ export type TravelId = number;
|
||||
|
||||
export class Travel {
|
||||
constructor(
|
||||
public id: TravelId = -1,
|
||||
public id: TravelId = null,
|
||||
public driverInfo: User = null,
|
||||
public travelersInfo: User[] = [],
|
||||
public departureDate: string = '',
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { User } from '../entities/user';
|
||||
import { OidcSecurityService } from 'angular-auth-oidc-client';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import { User } from '../entities/user';
|
||||
import { ApiService } from './api.service';
|
||||
import { ChatService } from './chat.service';
|
||||
|
||||
export enum AuthState {
|
||||
@@ -14,8 +15,6 @@ export enum AuthState {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
private checkAuth: Observable<any>;
|
||||
|
||||
private loggedSubject = new BehaviorSubject<boolean>(false);
|
||||
public logged$ = this.loggedSubject.asObservable();
|
||||
|
||||
@@ -24,6 +23,7 @@ export class AuthService {
|
||||
|
||||
constructor(
|
||||
private oidcSecurityService: OidcSecurityService,
|
||||
private apiService: ApiService,
|
||||
private chatService: ChatService
|
||||
) { }
|
||||
|
||||
@@ -40,23 +40,34 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async configureAndTryLogin(chatLoginToken: string): Promise<AuthState> {
|
||||
this.checkAuth = this.oidcSecurityService.checkAuth();
|
||||
const checkAuthSubject = new Subject<boolean>();
|
||||
this.oidcSecurityService.checkAuth().subscribe(checkAuthSubject);
|
||||
|
||||
this.checkAuth.subscribe((auth) => {
|
||||
checkAuthSubject.subscribe((auth) => {
|
||||
console.log('is authenticated', auth);
|
||||
this.loggedSubject.next(auth);
|
||||
if (auth) {
|
||||
this.apiService.getUser().subscribe();
|
||||
}
|
||||
});
|
||||
this.oidcSecurityService.userData$.subscribe((claims) => {
|
||||
console.log(claims);
|
||||
console.log('name=' + User.fromClaims(claims)?.name);
|
||||
this.userSubject.next(User.fromClaims(claims));
|
||||
if (claims == null) {
|
||||
this.loggedSubject.next(false);
|
||||
}
|
||||
});
|
||||
this.oidcSecurityService.isAuthenticated$.subscribe((auth) => {
|
||||
console.log('isAuthenticated', auth);
|
||||
this.loggedSubject.next(auth);
|
||||
});
|
||||
|
||||
return this.checkAuth.toPromise().then((auth) => {
|
||||
return checkAuthSubject.toPromise().then((auth) => {
|
||||
console.log('is authenticated2', auth);
|
||||
|
||||
if (auth) {
|
||||
this.loggedSubject.next(true);
|
||||
// this.loggedSubject.next(true);
|
||||
return AuthState.Logged;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user