mirror of
https://github.com/bitwarden/desktop.git
synced 2024-09-07 00:38:13 +02:00
always set new tokens on refreshes
This commit is contained in:
parent
5a905bb4c1
commit
bc98c82303
@ -102,8 +102,9 @@ export default class ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshIdentityToken(): Promise<any> {
|
async refreshIdentityToken(): Promise<any> {
|
||||||
const response = await this.doRefreshToken();
|
try {
|
||||||
if (response.status !== 200) {
|
await this.doRefreshToken();
|
||||||
|
} catch (e) {
|
||||||
return Promise.reject(null);
|
return Promise.reject(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,21 +381,19 @@ export default class ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleTokenState(): Promise<string> {
|
private async handleTokenState(): Promise<string> {
|
||||||
const accessToken = await this.tokenService.getToken();
|
let accessToken: string;
|
||||||
if (!this.tokenService.tokenNeedsRefresh()) {
|
if (this.tokenService.tokenNeedsRefresh()) {
|
||||||
return 'Bearer ' + accessToken;
|
const tokenResponse = await this.doRefreshToken();
|
||||||
|
accessToken = tokenResponse.accessToken;
|
||||||
|
} else {
|
||||||
|
accessToken = await this.tokenService.getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.doRefreshToken();
|
return 'Bearer ' + accessToken;
|
||||||
const responseJson = await response.json();
|
|
||||||
const tokenResponse = new IdentityTokenResponse(responseJson);
|
|
||||||
await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken);
|
|
||||||
return 'Bearer ' + tokenResponse.accessToken;
|
|
||||||
|
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
private async doRefreshToken(): Promise<Response> {
|
private async doRefreshToken(): Promise<IdentityTokenResponse> {
|
||||||
const refreshToken = await this.tokenService.getRefreshToken();
|
const refreshToken = await this.tokenService.getRefreshToken();
|
||||||
if (refreshToken == null || refreshToken === '') {
|
if (refreshToken == null || refreshToken === '') {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
@ -415,7 +414,10 @@ export default class ApiService {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response;
|
const responseJson = await response.json();
|
||||||
|
const tokenResponse = new IdentityTokenResponse(responseJson);
|
||||||
|
await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken);
|
||||||
|
return tokenResponse;
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(response);
|
return Promise.reject(response);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user