Skip to content
Snippets Groups Projects
Commit 072fe02f authored by Chris Hines's avatar Chris Hines
Browse files

sessionToken is sometimes comming up null

parent 734e5207
No related branches found
No related tags found
1 merge request!117Revert "Revert "Add MLeRP Monash""
Pipeline #113041 passed
...@@ -45,6 +45,7 @@ export class AuthorisationService { ...@@ -45,6 +45,7 @@ export class AuthorisationService {
public loggedin$: BehaviorSubject<number>; public loggedin$: BehaviorSubject<number>;
public loggedout$: BehaviorSubject<number>; public loggedout$: BehaviorSubject<number>;
public sessionToken: string | null = null public sessionToken: string | null = null
public sessionToken$: BehaviorSubject<string|null> = new BehaviorSubject(null);
public availableKeys$: BehaviorSubject<any>; public availableKeys$: BehaviorSubject<any>;
private backendURI: string; private backendURI: string;
...@@ -83,7 +84,7 @@ export class AuthorisationService { ...@@ -83,7 +84,7 @@ export class AuthorisationService {
filter((v) => v !== null && v !== undefined), filter((v) => v !== null && v !== undefined),
take(1), take(1),
switchMap((v) => this.getSessionToken(v)) switchMap((v) => this.getSessionToken(v))
).subscribe((v) => { this.sessionToken = v; console.log('sub session token is',this.sessionToken); window.localStorage.setItem('strudel2_session', v); this.refresh() } ); ).subscribe((v) => { this.sessionToken = v; this.sessionToken$.next(v); console.log('sub session token is',this.sessionToken); window.localStorage.setItem('strudel2_session', v); this.refresh() } );
// every time the list of certs/keys changes update the list of whats logged in and out // every time the list of certs/keys changes update the list of whats logged in and out
// sshAuthzServers$ won't really "change" except that it needs to be retrieved first time // sshAuthzServers$ won't really "change" except that it needs to be retrieved first time
...@@ -151,7 +152,7 @@ public logout() { ...@@ -151,7 +152,7 @@ public logout() {
tap((v) => this.sessionToken = null), tap((v) => this.sessionToken = null),
switchMap((v) => this.getSessionToken(this.backendURI)) switchMap((v) => this.getSessionToken(this.backendURI))
). ).
subscribe((v) =>{ this.sessionToken = v ; window.localStorage.setItem('strudel2_session',v) ; this.refresh() } ) subscribe((v) =>{ this.sessionToken = v ; this.sessionToken$.next(v); window.localStorage.setItem('strudel2_session',v) ; this.refresh() } )
} }
private getSessionToken(apiserver: any): Observable<any> { private getSessionToken(apiserver: any): Observable<any> {
...@@ -248,6 +249,7 @@ private getSessionToken(apiserver: any): Observable<any> { ...@@ -248,6 +249,7 @@ private getSessionToken(apiserver: any): Observable<any> {
} }
if (error.stats == 401) { if (error.stats == 401) {
this.sessionToken = null; this.sessionToken = null;
this.sessionToken$.next(null);
console.log('session expired, why hasnt it refreshed automatically?') console.log('session expired, why hasnt it refreshed automatically?')
} }
this.notifications.notify("Error querying ssh agent"); this.notifications.notify("Error querying ssh agent");
...@@ -275,7 +277,7 @@ private getSessionToken(apiserver: any): Observable<any> { ...@@ -275,7 +277,7 @@ private getSessionToken(apiserver: any): Observable<any> {
} }
let headers = new HttpHeaders({ let headers = new HttpHeaders({
'Authorization': `Bearer ${this.sessionToken}` 'Authorization': `Bearer ${this.sessionToken$.value}`
}); });
let options = { headers: headers, withCredentials: true}; let options = { headers: headers, withCredentials: true};
let agentquery$ = this.http.get<any>(apiserver+'/sshagent',options) let agentquery$ = this.http.get<any>(apiserver+'/sshagent',options)
...@@ -305,11 +307,11 @@ private getSessionToken(apiserver: any): Observable<any> { ...@@ -305,11 +307,11 @@ private getSessionToken(apiserver: any): Observable<any> {
private killAgent() { private killAgent() {
this.notifications.notify("Logging out") this.notifications.notify("Logging out")
var anyvar: any; var anyvar: any;
if (this.sessionToken === null) { if (this.sessionToken$.value === null) {
return throwError('cant get the agent contents without a session'); return throwError('cant get the agent contents without a session');
} }
let headers = new HttpHeaders({ let headers = new HttpHeaders({
'Authorization': `Bearer ${this.sessionToken}` 'Authorization': `Bearer ${this.sessionToken$.value}`
}); });
let options = { headers: headers, withCredentials: true}; let options = { headers: headers, withCredentials: true};
...@@ -364,8 +366,8 @@ private getSessionToken(apiserver: any): Observable<any> { ...@@ -364,8 +366,8 @@ private getSessionToken(apiserver: any): Observable<any> {
tap(([key,cert,token]) => this.logout_sshauthz(token.sshauthzservice)), tap(([key,cert,token]) => this.logout_sshauthz(token.sshauthzservice)),
); );
let agent$ = combineLatest([keycert$.pipe(filter((v) => v !== null)),apiserver$]).pipe( let agent$ = combineLatest([keycert$.pipe(filter((v) => v !== null)),apiserver$,this.sessionToken$.pipe(filter((v) => v !== null))]).pipe(
switchMap(([keycert,apiserver]) => this.addCert(keycert,apiserver)), switchMap(([keycert,apiserver,sessionToken]) => this.addCert(keycert,apiserver)),
tap((v) => this.refresh()), tap((v) => this.refresh()),
tap((v)=>console.log('posted cert to agent',v)), tap((v)=>console.log('posted cert to agent',v)),
//switchMap((_) => this.updateAgentContents()), //switchMap((_) => this.updateAgentContents()),
...@@ -438,14 +440,14 @@ private getSessionToken(apiserver: any): Observable<any> { ...@@ -438,14 +440,14 @@ private getSessionToken(apiserver: any): Observable<any> {
return this.ipcService.addCert(data); return this.ipcService.addCert(data);
} else { } else {
console.log('adding the certificate, session token is ',this.sessionToken); console.log('adding the certificate, session token is ',this.sessionToken$.value);
if (this.sessionToken === null) { if (this.sessionToken === null) {
throwError('Session token is null how is this possible') throwError('Session token is null how is this possible')
} }
let headers = new HttpHeaders({ let headers = new HttpHeaders({
'Authorization': `Bearer ${this.sessionToken}` 'Authorization': `Bearer ${this.sessionToken$.value}`
}); });
let options = { headers: headers, withCredentials: true}; let options = { headers: headers, withCredentials: true};
let data = {'key': keyCert.key, 'cert': keyCert.cert}; let data = {'key': keyCert.key, 'cert': keyCert.cert};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment