Skip to content

Latest commit

 

History

History
476 lines (372 loc) · 32.6 KB

File metadata and controls

476 lines (372 loc) · 32.6 KB

OAuth

(oAuth)

Overview

OAuth authorization flow

Available Operations

postOAuthRegister

Register an OAuth client dynamically (RFC 7591). Used by MCP clients like ChatGPT and Claude.

Example Usage

import { Midday } from "@midday-ai/sdk";

const midday = new Midday({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const result = await midday.oAuth.postOAuthRegister({
    clientName: "ChatGPT",
    redirectUris: [
      "https://chatgpt.com/connector/oauth/callback",
    ],
    grantTypes: [
      "authorization_code",
      "refresh_token",
    ],
    scope: "transactions.read invoices.read",
    logoUri: "https://example.com/logo.png",
    clientUri: "https://example.com",
    responseTypes: [
      "code",
    ],
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { MiddayCore } from "@midday-ai/sdk/core.js";
import { oAuthPostOAuthRegister } from "@midday-ai/sdk/funcs/oAuthPostOAuthRegister.js";

// Use `MiddayCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const midday = new MiddayCore({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const res = await oAuthPostOAuthRegister(midday, {
    clientName: "ChatGPT",
    redirectUris: [
      "https://chatgpt.com/connector/oauth/callback",
    ],
    grantTypes: [
      "authorization_code",
      "refresh_token",
    ],
    scope: "transactions.read invoices.read",
    logoUri: "https://example.com/logo.png",
    clientUri: "https://example.com",
    responseTypes: [
      "code",
    ],
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("oAuthPostOAuthRegister failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.PostOAuthRegisterRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.PostOAuthRegisterResponse>

Errors

Error Type Status Code Content Type
errors.OAuthErrorResponse 400 application/json
errors.APIError 4XX, 5XX */*

getOAuthAuthorization

Initiate OAuth authorization flow and get consent screen information

Example Usage

import { Midday } from "@midday-ai/sdk";

const midday = new Midday({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const result = await midday.oAuth.getOAuthAuthorization({
    responseType: "code",
    clientId: "mid_client_abcdef123456789",
    redirectUri: "https://myapp.com/callback",
    scope: "transactions.read invoices.read",
    state: "abc123xyz789_secure-random-state-value",
    codeChallenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
    codeChallengeMethod: "S256",
    resource: "https://api.midday.ai",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { MiddayCore } from "@midday-ai/sdk/core.js";
import { oAuthGetOAuthAuthorization } from "@midday-ai/sdk/funcs/oAuthGetOAuthAuthorization.js";

// Use `MiddayCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const midday = new MiddayCore({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const res = await oAuthGetOAuthAuthorization(midday, {
    responseType: "code",
    clientId: "mid_client_abcdef123456789",
    redirectUri: "https://myapp.com/callback",
    scope: "transactions.read invoices.read",
    state: "abc123xyz789_secure-random-state-value",
    codeChallenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
    codeChallengeMethod: "S256",
    resource: "https://api.midday.ai",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("oAuthGetOAuthAuthorization failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.GetOAuthAuthorizationRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.GetOAuthAuthorizationResponse>

Errors

Error Type Status Code Content Type
errors.OAuthErrorResponse 400 application/json
errors.APIError 4XX, 5XX */*

postOAuthAuthorization

Process user's authorization decision (allow/deny)

Example Usage

import { Midday } from "@midday-ai/sdk";

const midday = new Midday({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const result = await midday.oAuth.postOAuthAuthorization({
    clientId: "mid_client_abcdef123456789",
    decision: "allow",
    scopes: [
      "transactions.read",
      "invoices.read",
    ],
    redirectUri: "https://myapp.com/callback",
    state: "abc123xyz789_secure-random-state-value",
    codeChallenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
    teamId: "123e4567-e89b-12d3-a456-426614174000",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { MiddayCore } from "@midday-ai/sdk/core.js";
import { oAuthPostOAuthAuthorization } from "@midday-ai/sdk/funcs/oAuthPostOAuthAuthorization.js";

// Use `MiddayCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const midday = new MiddayCore({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const res = await oAuthPostOAuthAuthorization(midday, {
    clientId: "mid_client_abcdef123456789",
    decision: "allow",
    scopes: [
      "transactions.read",
      "invoices.read",
    ],
    redirectUri: "https://myapp.com/callback",
    state: "abc123xyz789_secure-random-state-value",
    codeChallenge: "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
    teamId: "123e4567-e89b-12d3-a456-426614174000",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("oAuthPostOAuthAuthorization failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.PostOAuthAuthorizationRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.PostOAuthAuthorizationResponse>

Errors

Error Type Status Code Content Type
errors.PostOAuthAuthorizationBadRequestError 400 application/json
errors.PostOAuthAuthorizationUnauthorizedError 401 application/json
errors.APIError 4XX, 5XX */*

postOAuthToken

Exchange authorization code for access token or refresh an access token

Example Usage

import { Midday } from "@midday-ai/sdk";

const midday = new Midday({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const result = await midday.oAuth.postOAuthToken({
    grantType: "refresh_token",
    refreshToken: "mid_rt_abcdef123456789",
    clientId: "mid_client_abcdef123456789",
    clientSecret: "mid_secret_abcdef123456789",
    scope: "transactions.read invoices.read",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { MiddayCore } from "@midday-ai/sdk/core.js";
import { oAuthPostOAuthToken } from "@midday-ai/sdk/funcs/oAuthPostOAuthToken.js";

// Use `MiddayCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const midday = new MiddayCore({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const res = await oAuthPostOAuthToken(midday, {
    grantType: "refresh_token",
    refreshToken: "mid_rt_abcdef123456789",
    clientId: "mid_client_abcdef123456789",
    clientSecret: "mid_secret_abcdef123456789",
    scope: "transactions.read invoices.read",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("oAuthPostOAuthToken failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.OAuthTokenEndpointRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.PostOAuthTokenResponse>

Errors

Error Type Status Code Content Type
errors.OAuthErrorResponse 400 application/json
errors.APIError 4XX, 5XX */*

postOAuthRevoke

Revoke an access token or refresh token

Example Usage

import { Midday } from "@midday-ai/sdk";

const midday = new Midday({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const result = await midday.oAuth.postOAuthRevoke({
    token: "mid_access_token_abcdef123456789",
    tokenTypeHint: "access_token",
    clientId: "mid_client_abcdef123456789",
    clientSecret: "mid_secret_abcdef123456789",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { MiddayCore } from "@midday-ai/sdk/core.js";
import { oAuthPostOAuthRevoke } from "@midday-ai/sdk/funcs/oAuthPostOAuthRevoke.js";

// Use `MiddayCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const midday = new MiddayCore({
  security: {
    oauth2: process.env["MIDDAY_OAUTH2"] ?? "",
  },
});

async function run() {
  const res = await oAuthPostOAuthRevoke(midday, {
    token: "mid_access_token_abcdef123456789",
    tokenTypeHint: "access_token",
    clientId: "mid_client_abcdef123456789",
    clientSecret: "mid_secret_abcdef123456789",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("oAuthPostOAuthRevoke failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.PostOAuthRevokeRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.PostOAuthRevokeResponse>

Errors

Error Type Status Code Content Type
errors.APIError 4XX, 5XX */*