コンテンツにスキップ
NextAuth.js v4 からの移行ですか? 移行ガイド.

NetSuite

⚠️
next-auth@5.0.0-beta.18 でリリース予定

リソース

セットアップ

コールバックURL

https://example.com/api/auth/callback/netsuite

NetSuite は http:// コールバック URL をサポートしていません。ローカルでテストする場合は、ngrok のようなサービスを使用してローカルの https URL を取得できます。

環境変数

AUTH_NETSUITE_ID
AUTH_NETSUITE_SECRET
AUTH_NETSUITE_ACCOUNT_ID

設定

プロバイダーを設定する前に、次の設定が完了していることを確認する必要があります。

  • 統合レコードを作成する
    • TBA 認証フローチェックボックスをオフにします。
    • OAuth 2.0 認証フローチェックボックスをオンにします。
    • 下の コールバックURL をコピーして、リダイレクトURI フィールドに貼り付けます。
    • 次に、使用するスコープを選択します。
      • REST Web サービス (rest_webservices) - REST Web サービスへのアクセス。
      • RESTlets(restlets) - RESTLets へのアクセス。
      • SuiteAnalytics Connect (suiteanalytics_connect) - SuiteAnalytics Connect へのアクセス。
    • 使用するポリシーを追加します。
      • アプリケーションロゴ (オプション) (ユーザーがアプリケーションへのアクセスを許可するように求められたときに表示されます)。 - 同意画面
      • アプリケーション利用規約 (オプション) - アプリケーションの利用規約を含む PDF ファイル。 - 同意画面
      • アプリケーションプライバシーポリシー (オプション) - アプリケーションのプライバシーポリシーを含む PDF ファイル。 - 同意画面
    • OAuth 2.0 同意ポリシーの設定 - この設定により、ユーザーがサインインするたび、またはサインイン時の最初の 1 回のみ、またはまったく許可を求めるかどうかを決定します。
    • 統合レコードを保存します。
    • 統合レコードは、プロバイダーの clientIdclientSecret を生成するために使用されます。生成された値は後で使用するために保存してください

Userinfo RESTLet ハンドラー

このプロバイダーを使用するには、NetSuite インスタンスで userinfo RESTLet を作成する必要があります。 当社の userinfo URL は、ユーザーに関する情報を取得するためのスイートレットまたは RESTLet URL である必要があります。 最適な方法は、最初に N/runtime モジュールを使用して基本情報を取得することです。以下に RESTLet の例を示します。必ずデプロイし、「すべてのロール」へのアクセスを有効にしてください。

URI の使用には、必ず外部 RESTLet URL をデプロイして使用してください。

/**
 * @NApiVersion 2.1
 * @NScriptType Restlet
 */
define(["N/runtime"],
 (runtime) => {
/**
 * Defines the function that is executed when a GET request is sent to a RESTlet.
 * @param {Object} requestParams - Parameters from HTTP request URL; parameters passed as an Object (for all supported
 *     content types)
 * @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an
 *     Object when request Content-Type is 'application/json' or 'application/xml'
 * @since 2015.2
 */
  const get = (requestParams) => {
    let userObject = runtime.getCurrentUser();
 
    try {
      log.debug({ title: "Payload received:", details: requestParams });
 
      const { id, name, role, location, email, contact } = userObject;
 
      log.audit({ title: "Current User Ran", details: name });
 
      let user = {
        id,
        name,
        role,
        location,
        email,
        contact,
      };
 
      log.debug({ title: "Returning user", details: user });
 
      return JSON.stringify(user);
    } catch (e) {
      log.error({ title: "Error grabbing current user:", details: e });
    }
  };
 
  return {
    get,
  };
);

上記は、基本的なランタイム情報を返す例です。必ず新しいスクリプト レコードとデプロイメント レコードを作成してください。デプロイメント レコードを保存すると、RESTLet の URL が取得され、これを userinfo URL として使用します。

使用例

@auth.ts
import NextAuth from "next-auth"
import NetSuite from "next-auth/providers/netsuite"
 
export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [
    NetSuite({
      clientId: process.env.AUTH_NETSUITE_ID,
      clientSecret: process.env.AUTH_NETSUITE_SECRET,
      issuer: process.env.AUTH_NETSUITE_ACCOUNT_ID, // EX: TSTDRV1234567 or 81555 for prod, and 1234567-SB1 for Sandbox accounts not "_" use "-".
      // Returns the current user using the N/runtime module. This url can be a suitelet or RESTlet (Recommended)
      // Using getCurrentUser(); So we match this schema returned from this RESTlet in the profile callback. (Required)
      userinfo:
        "https://1234567.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=1",
      // Optional
      prompt: "login", // Required if you want to force the user to login every time.
      scope: "restlets", // Optional defaults to "restlets rest_webservices". Enter the scope(s) you want to use followed by spaces.
    }),
  ],
})
Auth.js © Balázs Orbán およびチーム -2024