Skip to content

Commit 0186466

Browse files
committed
extend core sdk configuration to support server-side auth
1 parent 303a6c1 commit 0186466

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

packages/sdk/src/auth/token-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ export class CachedTokenProvider extends TokenProvider {
6666
async get(): Promise<Token> {
6767
const existingToken = this.getCachedToken();
6868
const subject = this.subject.toString();
69-
if (existingToken && this.tokenValidator.isValid(existingToken)) {
69+
70+
if (
71+
existingToken &&
72+
this.tokenValidator.canValidate(existingToken.header) &&
73+
this.tokenValidator.isSignatureValid(existingToken)
74+
) {
7075
return existingToken;
7176
}
7277
const existingDelegatePromise = this.delegateGetPromises[subject];

packages/sdk/src/auth/token-validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export abstract class TokenValidator {
2222
return true;
2323
}
2424

25-
private isExpired(token: Token) {
25+
isExpired(token: Token) {
2626
const nowUtcSeconds = new Date().getTime() / 1000;
2727
const delta = 10;
2828
return nowUtcSeconds + delta > token.body.exp;

packages/sdk/src/internal/sdk/sdk-factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import type { EncryptionKeysProvider } from '../../encryption/encryption-keys-pr
4444
import { DataServiceApiFactory } from '../../dialect-cloud-api/data-service-api-factory';
4545
import type { DataServiceApi } from '../../dialect-cloud-api/data-service-api';
4646
import { DataServiceWalletsApiClientV1 } from '../../dialect-cloud-api/data-service-wallets-api.v1';
47-
import { isBoolean } from '../../utils/typecheck';
4847

4948
export class InternalDialectSdk<ChainSdk extends BlockchainSdk>
5049
implements DialectSdk<ChainSdk>
@@ -273,6 +272,7 @@ export class DialectSdkFactory<ChainSdk extends BlockchainSdk> {
273272
const baseConfig: DialectCloudConfig = {
274273
environment: 'production',
275274
url: 'https://dialectapi.to',
275+
v2Url: 'https://alerts.dialectapi.to',
276276
tokenStore: this.createTokenStore(),
277277
tokenLifetimeMinutes: this.createTokenLifetime(),
278278
walletCreation: 'implicit',
@@ -283,25 +283,31 @@ export class DialectSdkFactory<ChainSdk extends BlockchainSdk> {
283283
}
284284
if (environment === 'production') {
285285
baseConfig.url = 'https://dialectapi.to';
286+
baseConfig.v2Url = 'https://alerts.dialectapi.to';
286287
}
287288
if (environment === 'development') {
288289
baseConfig.url = 'https://dev.dialectapi.to';
290+
baseConfig.v2Url = 'https://alerts.dev.dialectapi.to';
289291
}
290292
if (environment === 'local-development') {
291293
baseConfig.url = 'http://localhost:8080';
294+
baseConfig.v2Url = 'http://localhost:3003';
292295
}
293296
const dialectCloudEnvironment = this.config.dialectCloud?.environment;
294297
if (dialectCloudEnvironment) {
295298
baseConfig.environment = dialectCloudEnvironment;
296299
}
297300
if (dialectCloudEnvironment === 'production') {
298301
baseConfig.url = 'https://dialectapi.to';
302+
baseConfig.v2Url = 'https://alerts.dialectapi.to';
299303
}
300304
if (dialectCloudEnvironment === 'development') {
301305
baseConfig.url = 'https://dev.dialectapi.to';
306+
baseConfig.v2Url = 'https://alerts.dev.dialectapi.to';
302307
}
303308
if (dialectCloudEnvironment === 'local-development') {
304309
baseConfig.url = 'http://localhost:8080';
310+
baseConfig.v2Url = 'http://localhost:3003';
305311
}
306312
if (this.config.dialectCloud?.url) {
307313
baseConfig.url = this.config.dialectCloud.url;

packages/sdk/src/sdk/sdk.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export interface Config extends ConfigProps {
106106
export interface DialectCloudConfig extends DialectCloudConfigProps {
107107
environment: DialectCloudEnvironment;
108108
url: string;
109+
v2Url: string;
109110
tokenStore: TokenStore;
110111
tokenLifetimeMinutes: number;
111112
walletCreation: WalletCreation;

0 commit comments

Comments
 (0)