Skip to content

Commit

Permalink
fix(server): [nan-1167] fix types (#2295)
Browse files Browse the repository at this point in the history
## Describe your changes
Types lied and incorrect access was attempted.

## Issue ticket number and link
NAN-1167

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [ ] I added tests, otherwise the reason is: 
- [ ] I added observability, otherwise the reason is:
- [ ] I added analytics, otherwise the reason is:
  • Loading branch information
khaliqgant authored Jun 10, 2024
1 parent c679f16 commit c1b363c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/server/lib/clients/oauth1.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class OAuth1Client {

this.client = new oAuth1.OAuth(
this.authConfig.request_url,
typeof this.authConfig.token_url === 'string' ? this.authConfig.token_url : (this.authConfig.token_url?.['OAuth1'] as string),
typeof this.authConfig.token_url === 'string' ? this.authConfig.token_url : (this.authConfig.token_url?.['OAUTH1'] as string),
this.config.oauth_client_id,
this.config.oauth_client_secret,
'1.0A',
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/controllers/appAuth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AppAuthController {
await logCtx.enrichOperation({ integrationId: config.id!, integrationName: config.unique_key, providerName: config.provider });

const template = configService.getTemplate(config.provider);
const tokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url?.['App'] as string);
const tokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url?.['APP'] as string);

if (template.auth_mode !== 'APP') {
await createActivityLogMessageAndEnd({
Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class OAuthController {
const channel = session.webSocketClientId;
const providerConfigKey = session.providerConfigKey;
const connectionId = session.connectionId;
const tokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url?.['OAuth2'] as string);
const tokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url?.['OAUTH2'] as string);

try {
if (missesInterpolationParam(template.authorization_url!, connectionConfig)) {
Expand Down Expand Up @@ -1313,7 +1313,7 @@ class OAuthController {
tokenParams: template.token_params
});

const tokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url?.['OAuth2'] as string);
const tokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url?.['OAUTH2'] as string);

if (providerClientManager.shouldUseProviderClient(session.provider)) {
rawCredentials = await providerClientManager.getToken(config, tokenUrl, code as string, session.callbackUrl, session.codeVerifier);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/clients/oauth2.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getSimpleOAuth2ClientConfig(
template: ProviderTemplate,
connectionConfig: Record<string, string>
): Merge<ModuleOptions, { http: WreckHttpOptions }> {
const templateTokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url!['OAuth2'] as string);
const templateTokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url!['OAUTH2'] as string);
const strippedTokenUrl = templateTokenUrl.replace(/connectionConfig\./g, '');
const tokenUrl = new URL(interpolateString(strippedTokenUrl, connectionConfig));
const strippedAuthorizeUrl = template.authorization_url!.replace(/connectionConfig\./g, '');
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/lib/services/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ class ConnectionService {
connectionConfig: Connection['connection_config'],
privateKey: string
): Promise<ServiceResponse<AppStoreCredentials>> {
const templateTokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url!['AppStore'] as string);
const templateTokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url!['APP_STORE'] as string);
const tokenUrl = interpolateStringFromObject(templateTokenUrl, { connectionConfig });

const now = Math.floor(Date.now() / 1000);
Expand Down Expand Up @@ -993,7 +993,7 @@ class ConnectionService {
config: ProviderConfig,
connectionConfig: Connection['connection_config']
): Promise<ServiceResponse<AppCredentials>> {
const templateTokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url!['App'] as string);
const templateTokenUrl = typeof template.token_url === 'string' ? template.token_url : (template.token_url!['APP'] as string);

const tokenUrl = interpolateStringFromObject(templateTokenUrl, { connectionConfig });
const privateKeyBase64 = config?.custom ? config.custom['private_key'] : config.oauth_client_secret;
Expand Down
18 changes: 9 additions & 9 deletions packages/types/lib/integration/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import type { AuthModeType, OAuthAuthorizationMethodType, OAuthBodyFormatType }
import type { EndpointMethod } from '../api.js';

export interface TokenUrlObject {
OAuth1?: string;
OAuth2?: string;
OAuth2CC?: string;
Basic?: string;
ApiKey?: string;
AppStore?: string;
Custom?: string;
App?: string;
None?: string;
OAUTH1?: string;
OAUTH2?: string;
OAUTH2CC?: string;
BASIC?: string;
API_KEY?: string;
APP_STORE?: string;
CUSTOM?: string;
APP?: string;
NONE?: string;
}

export interface Template {
Expand Down

0 comments on commit c1b363c

Please sign in to comment.