Skip to content

Commit

Permalink
fix(cacheClient): recalculate identity token on login
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Nov 17, 2021
1 parent cfc962e commit aaaf929
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
Expand Up @@ -54,7 +54,6 @@
- [login](modules_cacheClient_cacheClient_service.CacheClient.md#login)
- [rejectClaim](modules_cacheClient_cacheClient_service.CacheClient.md#rejectclaim)
- [requestClaim](modules_cacheClient_cacheClient_service.CacheClient.md#requestclaim)
- [testLogin](modules_cacheClient_cacheClient_service.CacheClient.md#testlogin)

## Constructors

Expand Down Expand Up @@ -764,17 +763,3 @@ ___
#### Implementation of

[ICacheClient](../interfaces/modules_cacheClient_ICacheClient.ICacheClient.md).[requestClaim](../interfaces/modules_cacheClient_ICacheClient.ICacheClient.md#requestclaim)

___

### testLogin

**testLogin**(): `Promise`<`void`\>

#### Returns

`Promise`<`void`\>

#### Implementation of

[ICacheClient](../interfaces/modules_cacheClient_ICacheClient.ICacheClient.md).[testLogin](../interfaces/modules_cacheClient_ICacheClient.ICacheClient.md#testlogin)
Expand Up @@ -45,7 +45,6 @@
- [login](modules_cacheClient_ICacheClient.ICacheClient.md#login)
- [rejectClaim](modules_cacheClient_ICacheClient.ICacheClient.md#rejectclaim)
- [requestClaim](modules_cacheClient_ICacheClient.ICacheClient.md#requestclaim)
- [testLogin](modules_cacheClient_ICacheClient.ICacheClient.md#testlogin)

## Properties

Expand Down Expand Up @@ -546,13 +545,3 @@ ___
#### Returns

`Promise`<`void`\>

___

### testLogin

**testLogin**(): `Promise`<`void`\>

#### Returns

`Promise`<`void`\>
1 change: 0 additions & 1 deletion src/modules/cacheClient/ICacheClient.ts
Expand Up @@ -10,7 +10,6 @@ import { SearchType } from ".";

export interface ICacheClient {
pubKeyAndIdentityToken: IPubKeyAndIdentityToken | undefined;
testLogin: () => Promise<void>;
login: () => Promise<void>;
isAuthEnabled: () => boolean;

Expand Down
18 changes: 11 additions & 7 deletions src/modules/cacheClient/cacheClient.service.ts
Expand Up @@ -87,14 +87,18 @@ export class CacheClient implements ICacheClient {
return Promise.reject(error);
}

async testLogin(): Promise<void> {
// Simple test to check if logged in or no. TODO: have dedicated endpoint on the cache-server
// If receive unauthorized response, expect that refreshToken() will be called
await this.getRoleDefinition("testing.if.logged.in");
}

async login() {
await this.testLogin();
const pubKeyAndIdentityToken = await this._signerService.publicKeyAndIdentityToken();
const {
data: { refreshToken, token },
} = await this.httpClient.post<{ token: string; refreshToken: string }>("/login", {
identityToken: pubKeyAndIdentityToken.identityToken,
});
this.refresh_token = refreshToken;
if (!this.isBrowser) {
this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
this.refresh_token = refreshToken;
}
}

async getRoleDefinition(namespace: string) {
Expand Down

0 comments on commit aaaf929

Please sign in to comment.