Skip to content

Commit

Permalink
Issue #521 Fix (#606)
Browse files Browse the repository at this point in the history
* initial commit

* parsing credentials before calling db method

* changed upsert method accordingly
  • Loading branch information
saquib1998 authored May 5, 2023
1 parent ff364e8 commit a373fc4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Empty file modified .husky/pre-commit
100755 → 100644
Empty file.
12 changes: 7 additions & 5 deletions packages/server/lib/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getAccount,
getConnectionMetadataFromTokenResponse
} from '../utils/utils.js';
import { ProviderConfig, ProviderTemplate, ProviderTemplateOAuth2, ProviderAuthModes, OAuthSession, OAuth1RequestTokenResult } from '../models.js';
import { ProviderConfig, ProviderTemplate, ProviderTemplateOAuth2, ProviderAuthModes, OAuthSession, OAuth1RequestTokenResult, AuthCredentials } from '../models.js';
import logger from '../utils/logger.js';
import type { NextFunction } from 'express';
import errorManager from '../utils/error.manager.js';
Expand Down Expand Up @@ -314,13 +314,14 @@ class OAuthController {
logger.debug(`OAuth 2 for ${providerConfigKey} (connection ${connectionId}) successful.`);

const tokenMetadata = getConnectionMetadataFromTokenResponse(rawCredentials, template);

var parsedRawCredentials : AuthCredentials = connectionService.parseRawCredentials(rawCredentials, ProviderAuthModes.OAuth2);

connectionService.upsertConnection(
connectionId,
providerConfigKey,
session.provider,
rawCredentials,
ProviderAuthModes.OAuth2,
parsedRawCredentials,
session.connectionConfig,
session.accountId,
{ ...callbackMetadata, ...tokenMetadata }
Expand Down Expand Up @@ -352,12 +353,13 @@ class OAuthController {
.then((accessTokenResult) => {
logger.debug(`OAuth 1.0a for ${providerConfigKey} (connection: ${connectionId}) successful.`);

let parsedAccessTokenResult = connectionService.parseRawCredentials(accessTokenResult, ProviderAuthModes.OAuth1);

connectionService.upsertConnection(
connectionId,
providerConfigKey,
session.provider,
accessTokenResult,
ProviderAuthModes.OAuth1,
parsedAccessTokenResult,
session.connectionConfig,
session.accountId,
metadata
Expand Down
5 changes: 2 additions & 3 deletions packages/server/lib/services/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class ConnectionService {
connectionId: string,
providerConfigKey: string,
provider: string,
rawCredentials: object,
authMode: ProviderAuthModes,
parsedRawCredentials: AuthCredentials,
connectionConfig: Record<string, string>,
accountId: number,
metadata: Record<string, string>
Expand All @@ -30,7 +29,7 @@ class ConnectionService {
encryptionManager.encryptConnection({
connection_id: connectionId,
provider_config_key: providerConfigKey,
credentials: this.parseRawCredentials(rawCredentials, authMode),
credentials: parsedRawCredentials,
connection_config: connectionConfig,
account_id: accountId,
metadata: metadata
Expand Down

0 comments on commit a373fc4

Please sign in to comment.