Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
fix: explicitly catch 400s from keycloak
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir authored and joshuawilson committed Apr 27, 2017
1 parent 3811c11 commit dd87861
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/app/auth/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class AuthenticationService {
if (token) {
if (!this.clearTimeoutId) {
// kick off initial token refresh
this.refreshTokens.next({"access_token": token} as Token);
this.refreshTokens.next({ "access_token": token } as Token);
this.setupRefreshTimer(15);
}
return true;
Expand Down Expand Up @@ -118,7 +118,15 @@ export class AuthenticationService {
this.clearTimeoutId = null;
this.setupRefreshTimer(token.expires_in);
return token;
}).subscribe(token => {
})
.catch(response => {
// Additionally catch a 400 from keycloak
if (response.status === 400) {
this.broadcaster.broadcast('authenticationError', response);
}
return Observable.of({} as Token);
})
.subscribe(token => {
// Refresh any federated tokens that we have
this.refreshTokens.next(token);
console.log('token refreshed at:' + Date.now());
Expand All @@ -141,13 +149,16 @@ export class AuthenticationService {
let options = new RequestOptions({ headers: headers });
return this.http.get(tokenUrl, options)
.map(response => processToken(response))
.catch(error => {
.catch(response => {
if (response.status === 400) {
this.broadcaster.broadcast('authenticationError', res);
}
return Observable.of({} as Token);
})
.do(token => localStorage.setItem(broker + '_token', token.access_token))
.map(t => t.access_token);
})
.publishReplay(1);
.publishReplay(1);
res.connect();
return res;
}
Expand Down

0 comments on commit dd87861

Please sign in to comment.