Skip to content

Commit

Permalink
Merge pull request #232 from HubSpot/bash/add-fixtures-to-fetch-scope…
Browse files Browse the repository at this point in the history
…-authorization

feat: add fixtures to fetch scope authorization data per portal and user
  • Loading branch information
b-ash authored Feb 5, 2025
2 parents 19a88a6 + f49c02d commit 84bb99c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions api/localDevAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ScopeData,
AccessTokenResponse,
EnabledFeaturesResponse,
ScopeAuthorizationResponse,
} from '../types/Accounts';
import axios from 'axios';
import { PublicAppInstallationData } from '../types/Apps';
Expand Down Expand Up @@ -44,6 +45,14 @@ export function fetchScopeData(
});
}

export async function fetchScopeAuthorizationData(
accountId: number
): HubSpotPromise<ScopeAuthorizationResponse> {
return http.get<ScopeAuthorizationResponse>(accountId, {
url: `${LOCALDEVAUTH_API_AUTH_PATH}/scope-groups/authorized`,
});
}

export function fetchAppInstallationData(
portalId: number,
projectId: number,
Expand Down
10 changes: 8 additions & 2 deletions lib/personalAccessKey.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import moment from 'moment';
import { ENVIRONMENTS } from '../constants/environments';
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from '../constants/auth';
import { fetchAccessToken } from '../api/localDevAuth';
import { fetchAccessToken, fetchScopeAuthorizationData } from '../api/localDevAuth';
import { fetchSandboxHubData } from '../api/sandboxHubs';
import { CLIAccount, PersonalAccessKeyAccount } from '../types/Accounts';
import { CLIAccount, PersonalAccessKeyAccount, ScopeGroupAuthorization } from '../types/Accounts';
import { Environment } from '../types/Config';
import {
getAccountConfig,
Expand Down Expand Up @@ -168,6 +168,12 @@ export async function scopesOnAccessToken(
return (await getNewAccessTokenByAccountId(accountId)).scopeGroups;
}

export async function authorizedScopesForPortalAndUser(
accountId: number
): Promise<Array<ScopeGroupAuthorization>> {
return (await fetchScopeAuthorizationData(accountId)).data.results;
}

export async function updateConfigWithAccessToken(
token: AccessToken,
personalAccessKey: string,
Expand Down
16 changes: 16 additions & 0 deletions types/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ export type ScopeData = {
userScopesInGroup: Array<string>;
};

export type ScopeAuthorizationResponse = {
results: Array<ScopeGroupAuthorization>;
}

export type ScopeGroupAuthorization = {
scopeGroup: ScopeGroup;
portalAuthorized: boolean;
userAuthorized: boolean;
}

export type ScopeGroup = {
name: string;
shortDescription: string;
longDescription: string;
}

export type AccessTokenResponse = {
hubId: number;
userId: number;
Expand Down

0 comments on commit 84bb99c

Please sign in to comment.