Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integrations): add TwoStep as a new auth_mode for Perimeter 81 #2868

Merged
merged 15 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs-v2/integrations/all/perimeter81.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Perimeter81
sidebarTitle: Perimeter81
---

API configuration: [`perimeter`](https://nango.dev/providers.yaml)

## Features

| Features | Status |
| - | - |
| [Auth (Perimeter)](/integrate/guides/authorize-an-api) | ✅ |
| [Sync data](/integrate/guides/sync-data-from-an-api) | ✅ |
| [Perform workflows](/integrate/guides/perform-workflows-with-an-api) | ✅ |
| [Proxy requests](/integrate/guides/proxy-requests-to-an-api) | ✅ |
| [Receive webhooks](/integrate/guides/receive-webhooks-from-an-api) | 🚫 (time to contribute: <48h) |

<Tip>We can implement missing features in &lt;48h, just ask for it in the [community](https://nango.dev/slack).</Tip>

## Getting started

- [Perimeter81 Authentication docs](https://support.perimeter81.com/docs/authorize)
- [Perimeter81 API docs](https://support.perimeter81.com/docs/api-3-old)

<Tip>Need help getting started? Get help in the [community](https://nango.dev/slack).</Tip>

## API gotchas

- When creating a new connection on Nango add `perimeter81` for US and `eu.sase.checkpoint` for EU tenants.

<Note>Add Getting Started links and Gotchas by [editing this page](https://github.com/nangohq/nango/tree/master/docs-v2/integrations/all/perimeter.mdx)</Note>
1 change: 1 addition & 0 deletions docs-v2/integrations/productivity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sidebarTitle: Productivity
<Card title="Notion" href="/integrations/all/notion" color="#68a063" />
<Card title="OneNote" href="/integrations/all/one-note" color="#68a063" />
<Card title="OpenAI" href="/integrations/all/openai" color="#68a063" />
<Card title="Perimeter81" href="/integrations/all/perimeter81" color="#68a063" />
<Card title="Perplexity" href="/integrations/all/perplexity" color="#68a063" />
<Card title="Pingboard" href="/integrations/all/pingboard" color="#68a063" />
<Card title="Pivotaltracker" href="/integrations/all/pivotaltracker" color="#68a063" />
Expand Down
1 change: 1 addition & 0 deletions docs-v2/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
"integrations/all/pennylane",
"integrations/all/personio",
"integrations/all/peopledatalabs",
"integrations/all/perimeter81",
"integrations/all/perplexity",
"integrations/all/pingboard",
"integrations/all/pinterest",
Expand Down
2 changes: 1 addition & 1 deletion docs-v2/reference/api-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ slack:
</ResponseField>

<ResponseField name="auth_mode" type="string" >
The authentication mode. Must be one of: "API_KEY", "APP", "APP_STORE", "BASIC", "NONE", "OAUTH1", "OAUTH2", "OAUTH2_CC", "CUSTOM", "TBA", "TABLEAU", "JWT", "BILL".
The authentication mode. Must be one of: "API_KEY", "APP", "APP_STORE", "BASIC", "NONE", "OAUTH1", "OAUTH2", "OAUTH2_CC", "CUSTOM", "TBA", "TABLEAU", "JWT", "BILL", "PERIMETER".
hassan254-prog marked this conversation as resolved.
Show resolved Hide resolved
</ResponseField>

<ResponseField name="auth" type="object">
Expand Down
2 changes: 1 addition & 1 deletion docs-v2/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ components:
type: string
auth_mode:
type: string
enum: ['OAUTH1','OAUTH2','OAUTH2_CC','BASIC','API_KEY','APP_STORE','CUSTOM','APP','NONE','TBA','TABLEAU','JWT','BILL']
enum: ['OAUTH1','OAUTH2','OAUTH2_CC','BASIC','API_KEY','APP_STORE','CUSTOM','APP','NONE','TBA','TABLEAU','JWT','BILL','PERIMETER']
hassan254-prog marked this conversation as resolved.
Show resolved Hide resolved
proxy:
properties:
base_url:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface AuthModes {
Tableau: 'TABLEAU';
Jwt: 'JWT';
Bill: 'BILL';
Perimeter: 'PERIMETER';
}
export type AuthModeType = AuthModes[keyof AuthModes];
interface OAuth1Token {
Expand Down Expand Up @@ -225,11 +226,17 @@ interface BillCredentials extends CredentialsCommon {
user_id?: string;
expires_at?: Date | undefined;
}
interface PerimeterCredentials extends CredentialsCommon {
type: AuthModes['Perimeter'];
api_key: string;
token?: string;
expires_at?: Date | undefined;
}
interface CustomCredentials extends CredentialsCommon {
type: AuthModes['Custom'];
}
type UnauthCredentials = Record<string, never>;
type AuthCredentials = OAuth2Credentials | OAuth2ClientCredentials | OAuth1Credentials | BasicApiCredentials | ApiKeyCredentials | AppCredentials | AppStoreCredentials | UnauthCredentials | TbaCredentials | TableauCredentials | JwtCredentials | BillCredentials | CustomCredentials;
type AuthCredentials = OAuth2Credentials | OAuth2ClientCredentials | OAuth1Credentials | BasicApiCredentials | ApiKeyCredentials | AppCredentials | AppStoreCredentials | UnauthCredentials | TbaCredentials | TableauCredentials | JwtCredentials | BillCredentials | PerimeterCredentials | CustomCredentials;
type Metadata = Record<string, unknown>;
interface MetadataChangeResponse {
metadata: Metadata;
Expand Down Expand Up @@ -349,7 +356,7 @@ export declare class NangoAction {
put<T = any>(config: Omit<ProxyConfiguration, 'method'>): Promise<AxiosResponse<T>>;
patch<T = any>(config: Omit<ProxyConfiguration, 'method'>): Promise<AxiosResponse<T>>;
delete<T = any>(config: Omit<ProxyConfiguration, 'method'>): Promise<AxiosResponse<T>>;
getToken(): Promise<string | OAuth1Token | OAuth2ClientCredentials | BasicApiCredentials | ApiKeyCredentials | AppCredentials | AppStoreCredentials | UnauthCredentials | CustomCredentials | TbaCredentials | TableauCredentials | JwtCredentials | BillCredentials>;
getToken(): Promise<string | OAuth1Token | OAuth2ClientCredentials | BasicApiCredentials | ApiKeyCredentials | AppCredentials | AppStoreCredentials | UnauthCredentials | CustomCredentials | TbaCredentials | TableauCredentials | JwtCredentials | BillCredentials | PerimeterCredentials>;
getConnection(providerConfigKeyOverride?: string, connectionIdOverride?: string): Promise<Connection>;
setMetadata(metadata: Metadata): Promise<AxiosResponse<MetadataChangeResponse>>;
updateMetadata(metadata: Metadata): Promise<AxiosResponse<MetadataChangeResponse>>;
Expand Down
3 changes: 3 additions & 0 deletions packages/connect-ui/src/views/Go.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const formSchema: Record<AuthModeType, z.AnyZodObject> = {
z.string()
])
}),
PERIMETER: z.object({
api_key: z.string().min(1)
}),
TBA: z.object({
oauth_client_id_override: z.string().min(1),
oauth_client_secret_override: z.string().min(1),
Expand Down
18 changes: 18 additions & 0 deletions packages/frontend/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
OAuth2ClientCredentials,
TBACredentials,
TableauCredentials,
PerimeterCredentials,
JwtCredentials,
OAuthCredentialsOverride,
BillCredentials
Expand Down Expand Up @@ -292,6 +293,7 @@ export default class Nango {
| JwtCredentials
| OAuth2ClientCredentials
| BillCredentials
| PerimeterCredentials
): ConnectionConfig {
const params: Record<string, string> = {};

Expand Down Expand Up @@ -377,6 +379,14 @@ export default class Nango {
return { params: tableauCredentials } as unknown as ConnectionConfig;
}

if ('api_key' in credentials) {
const perimeterCredentials: PerimeterCredentials = {
api_key: credentials.api_key
};

return { params: perimeterCredentials } as unknown as ConnectionConfig;
}
Copy link
Collaborator

@TBonnin TBonnin Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works only because no other credentials has a attribute called api_key in snake case. It is very fragile and might be a source of bugs if more credentials with an api_key attribute are added. This PR is probably not the place to refactor but a good refactoring of this function would be welcome. For instance credentials could bevalidated with the help of zod schemas


if ('username' in credentials && 'password' in credentials && 'organization_id' in credentials && 'dev_key' in credentials) {
const BillCredentials: BillCredentials = {
username: credentials.username,
Expand Down Expand Up @@ -405,6 +415,7 @@ export default class Nango {
| JwtCredentials
| BillCredentials
| OAuth2ClientCredentials
| PerimeterCredentials
| undefined;
}): Promise<AuthResult> {
const res = await fetch(authUrl, {
Expand Down Expand Up @@ -499,6 +510,13 @@ export default class Nango {
});
}

if ('api_key' in credentials) {
return await this.triggerAuth({
authUrl: this.hostBaseUrl + `/auth/perimeter/${providerConfigKey}${this.toQueryString(connectionId, connectionConfig as ConnectionConfig)}`,
credentials: credentials as unknown as PerimeterCredentials
});
}

return Promise.reject(new Error('Something went wrong with the authorization'));
}

Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ConnectionConfig {
| TBACredentials
| TableauCredentials
| JwtCredentials
| PerimeterCredentials
| OAuth2ClientCredentials;
}

Expand Down Expand Up @@ -94,6 +95,10 @@ export interface BillCredentials {
dev_key: string;
}

export interface PerimeterCredentials {
api_key: string;
}

export enum AuthorizationStatus {
IDLE,
BUSY,
Expand Down
4 changes: 3 additions & 1 deletion packages/node-client/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import type {
GetPublicListIntegrationsLegacy,
GetPublicIntegration,
PostConnectSessions,
JwtCredentials
JwtCredentials,
PerimeterCredentials
} from '@nangohq/types';
import type {
Connection,
Expand Down Expand Up @@ -325,6 +326,7 @@ export class Nango {
| TableauCredentials
| JwtCredentials
| BillCredentials
| PerimeterCredentials
> {
const response = await this.getConnectionDetails(providerConfigKey, connectionId, forceRefresh);

Expand Down
Loading
Loading