Skip to content

Commit

Permalink
🐛 Fix scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Apr 21, 2024
1 parent 23b0695 commit bca3f64
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/api/src/@core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class AuthService {
}
}

//TODO
async login(user: LoginDto) {
try {
let foundUser: User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,18 @@ export class ConnectionsStrategiesService {
CLIENT_SECRET: this.configService.get<string>(
`${provider.toUpperCase()}_${vertical.toUpperCase()}_${softwareMode.toUpperCase()}_CLIENT_SECRET`,
),
SCOPE:
providersConfig[vertical.toLowerCase()][provider.toLowerCase()]
.scopes,
};
const scopes =
providersConfig[vertical.toLowerCase()][provider.toLowerCase()]
.scopes;
if (scopes) {
data = {
...data,
SCOPE:
providersConfig[vertical.toLowerCase()][provider.toLowerCase()]
.scopes,
};
}
if (needsSubdomain(provider, vertical)) {
data = {
...data,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
redis: {
host: process.env.REDIS_HOST || 'redis',
port: Number(process.env.REDIS_PORT) || 6379,
password: process.env.REDIS_PASS
password: process.env.REDIS_PASS,
},
}),
],
Expand Down
6 changes: 2 additions & 4 deletions packages/shared/src/authUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const handleOAuth2Url = async (input: HandleOAuth2Url) => {

const { urls: urls } = config;
const { authBaseUrl: baseUrl } = urls;

if (!baseUrl) throw new Error(`No authBaseUrl found for type ${type}`)

// construct the baseAuthUrl based on the fact that client may use custom subdomain
Expand All @@ -113,10 +113,8 @@ const handleOAuth2Url = async (input: HandleOAuth2Url) => {
// Default URL structure
let params = `client_id=${encodeURIComponent(clientId)}&redirect_uri=${encodedRedirectUrl}&state=${state}`;

const providersWithoutScopes = ['pipedrive', 'clickup', 'aha', 'freeagent', 'teamwork', 'attio', 'close', 'teamleader', 'getresponse']

// Adding scope for providers that require it, except for 'pipedrive'
if (!providersWithoutScopes.includes(providerName)) {
if (scopes) {
params += `&scope=${encodeURIComponent(scopes)}`;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ApiAuthData = {
export type OAuth2AuthData = {
CLIENT_ID: string;
CLIENT_SECRET: string;
SCOPE: string;
SCOPE?: string;
SUBDOMAIN?: string;
}

Expand Down
17 changes: 4 additions & 13 deletions packages/shared/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum SoftwareMode {
}

export type ProviderConfig = {
scopes: string;
scopes?: string;
logoPath: string;
description: string;
active?: boolean;
Expand Down Expand Up @@ -38,7 +38,7 @@ export type ProvidersConfig = {
export const providersConfig: ProvidersConfig = {
'crm': {
'hubspot': {
scopes: 'crm.objects.contacts.read crm.objects.contacts.write crm.schemas.deals.read crm.schemas.deals.write crm.objects.deals.read crm.objects.deals.write crm.objects.companies.read crm.objects.companies.write crm.objects.owners.read settings.users.read settings.users.write settings.users.teams.read settings.users.teams.write',
scopes: 'crm.dealsplits.read_write crm.export crm.import crm.lists.read crm.lists.write crm.objects.carts.read crm.objects.carts.write crm.objects.commercepayments.read crm.objects.companies.read crm.objects.companies.write crm.objects.contacts.read crm.objects.contacts.write crm.objects.custom.read crm.objects.custom.write crm.objects.deals.read crm.objects.deals.write crm.objects.feedback_submissions.read crm.objects.goals.read crm.objects.invoices.read crm.objects.line_items.read crm.objects.line_items.write crm.objects.marketing_events.read crm.objects.marketing_events.write crm.objects.orders.read crm.objects.orders.write crm.objects.owners.read crm.objects.quotes.read crm.objects.quotes.write crm.objects.subscriptions.read crm.objects.users.read crm.objects.users.write crm.pipelines.orders.read crm.pipelines.orders.write crm.schemas.carts.read crm.schemas.carts.write crm.schemas.commercepayments.read crm.schemas.companies.read crm.schemas.companies.write crm.schemas.contacts.read crm.schemas.contacts.write crm.schemas.custom.read crm.schemas.deals.read crm.schemas.deals.write crm.schemas.invoices.read crm.schemas.line_items.read crm.schemas.orders.read crm.schemas.orders.write crm.schemas.quotes.read crm.schemas.subscriptions.read',
urls: {
docsUrl: 'https://developers.hubspot.com/docs/api/crm/understanding-the-crm',
authBaseUrl: 'https://app-eu1.hubspot.com/oauth/authorize',
Expand All @@ -50,7 +50,7 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'attio': {
scopes: 'record_permission:read',
//scopes: 'record_permission:read',
urls: {
docsUrl: 'https://developers.attio.com/reference',
authBaseUrl: 'https://app.attio.com/authorize',
Expand All @@ -74,7 +74,6 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'pipedrive': {
scopes: 'Pipedrive_Scope',
urls: {
docsUrl: 'https://developers.pipedrive.com/docs/api/v1',
authBaseUrl: 'https://oauth.pipedrive.com/oauth/authorize',
Expand Down Expand Up @@ -112,7 +111,6 @@ export const providersConfig: ProvidersConfig = {
},
'accelo': {
scopes: '',

urls: {
docsUrl: 'https://api.accelo.com/docs/#introduction',
authBaseUrl: '/oauth2/v0/authorize',
Expand Down Expand Up @@ -158,7 +156,6 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'close': {
scopes: '',
urls: {
docsUrl: 'https://developer.close.com/',
authBaseUrl: 'https://app.close.com/oauth2/authorize',
Expand Down Expand Up @@ -278,7 +275,6 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'teamleader': {
scopes: '',
urls: {
docsUrl: 'https://developer.teamleader.eu/#/introduction/ap-what?',
authBaseUrl: 'https://focus.teamleader.eu/oauth2/authorize',
Expand All @@ -290,7 +286,6 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'teamwork': {
scopes: '',
urls: {
docsUrl: 'https://apidocs.teamwork.com/guides/teamwork/getting-started-with-the-teamwork-com-api',
authBaseUrl: 'https://www.teamwork.com/launchpad/login',
Expand Down Expand Up @@ -409,7 +404,6 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'clickup': {
scopes: '',
urls: {
docsUrl: 'https://clickup.com/api/',
apiUrl: 'https://api.clickup.com/v2',
Expand All @@ -433,7 +427,6 @@ export const providersConfig: ProvidersConfig = {
authStrategy: AuthStrategy.oauth2
},
'aha': {
scopes: '',
urls: {
docsUrl: 'https://www.aha.io/api',
apiUrl: '/api/v1',
Expand Down Expand Up @@ -774,7 +767,6 @@ export const providersConfig: ProvidersConfig = {
active: false,
},
'freeagent': {
scopes: '',
urls: {
docsUrl: 'https://dev.freeagent.com/docs/quick_start',
apiUrl: 'https://api.freeagent.com/v2',
Expand Down Expand Up @@ -906,7 +898,6 @@ export const providersConfig: ProvidersConfig = {
active: false,
},
'getresponse': {
scopes: '',
urls: {
authBaseUrl: 'https://app.getresponse.com/oauth2_authorize.html',
docsUrl: 'https://apidocs.getresponse.com/v3',
Expand Down Expand Up @@ -2162,7 +2153,7 @@ interface Provider {
apiUrl: string;
authBaseUrl?: string | null;
};
scopes: string;
scopes?: string;
logoPath: string;
description?: string;
};
Expand Down

0 comments on commit bca3f64

Please sign in to comment.