メインコンテンツにスキップ

Joplin Server

Joplin はオープンソースのノート作成アプリであり、Joplin Server はそのセルフホスト型の同期サーバーです。バージョン 3.4.1 以降、Joplin Server は SAML 2.0 アイデンティティプロバイダー (IdP) を通じてユーザーをサインインさせることができます。Casdoor を IdP として使用することで、ユーザーは Casdoor アカウントで Joplin Server およびそれと同期する Joplin アプリにサインインできます。

Joplin Server は samlify と xml-crypto を使用して SAML レスポンスを検証します。xml-crypto は Casdoor がデフォルトで署名に使用する XML カノニカライゼーション 1.1 をサポートしていないため、Casdoor のアプリケーションでは Enable SAML C14N10 をオンにする必要があります。最新の Casdoor バージョンを使用してください。古いバージョンでは、Joplin Server が拒否する形式(FAILED_TO_VERIFY_SIGNATURE または XML スキーマエラー)でレスポンスに署名します。

例では、Joplin Server 用に https://joplin.example.com、Casdoor 用に https://door.example.com を使用しています。

Casdoor でアプリケーションを作成する​

  1. Casdoor 管理コンソールで、ユーザーの組織を開き、アプリケーションを追加するか、既存のアプリケーションを開きます。

  2. Joplin Server のエンティティ ID と Assertion Consumer Service (ACS) URL を Redirect URLs に追加します。エンティティ ID は、後述で作成するサービスプロバイダー (SP) ファイル内の entityID(例では Joplin)です。ACS URL は <APP_BASE_URL>/api/saml です:

    Joplin
    https://joplin.example.com/api/saml
  3. SAML タブで:

    • Enable SAML C14N10 をオンにし、SAML C14N10 prefix は空のままにします。

    • Enable SAML POST binding をオンにします。Joplin Server は HTTP-POST バインディングで Casdoor にリクエストを送信するため、メタデータには Casdoor の HTTP-POST エンドポイントが記載されている必要があります。

    • SAML attributes に 2 行を追加します。Joplin Server はこれらの 2 つの属性のみを読み取り、大文字小文字は区別されます。Casdoor がデフォルトで送信する Email および DisplayName 属性は対象外です。

      NameName formatValue
      emailBasic$user.email
      displayNameBasic$user.displayName

      すべてのユーザーは Casdoor にメールアドレスを持つ必要があります。Joplin Server はこれを使用してユーザーを識別します。

  4. 保存し、Copy SAML metadata URL をクリックします。Enable SAML POST binding がオンの場合、URL は enablePostBinding=true で終わります:

    https://door.example.com/api/saml/metadata?application=admin/<application-name>&enablePostBinding=true
  5. URL を開き、XML を idp.xml として保存します。Joplin Server は IdP メタデータをファイルから読み込み、URL からは読み込みません。

Joplin Server の準備​

  1. SP ファイル sp.xml を作成します。entityID に Redirect URLs に追加したエンティティ ID を、Location に ACS URL を設定します:

    <?xml version="1.0"?>
    <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="Joplin">
    <md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
    <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat>
    <md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://joplin.example.com/api/saml" index="1" />
    </md:SPSSODescriptor>
    </md:EntityDescriptor>
  2. idp.xml と sp.xml を、Joplin Server が読み取れる場所に配置します。Docker を使用する場合、例えば docker-compose.yml 内で ./saml:/saml:ro のようにディレクトリをマウントします。

  3. Joplin Server の環境変数を設定します。例えば .env ファイル内に設定します:

    APP_BASE_URL=https://joplin.example.com
    API_BASE_URL=https://joplin.example.com
    SAML_ENABLED=true
    SAML_IDP_CONFIG_FILE=/saml/idp.xml
    SAML_SP_CONFIG_FILE=/saml/sp.xml
    SAML_ORGANIZATION_DISPLAY_NAME=Casdoor
    DELETE_EXPIRED_SESSIONS_SCHEDULE=
    VariableDescription
    APP_BASE_URL, API_BASE_URLSAML needs both set to the same URL.
    SAML_ENABLEDTurns on SAML sign-in.
    SAML_IDP_CONFIG_FILEThe path of the IdP metadata from Casdoor.
    SAML_SP_CONFIG_FILEThe path of the SP file.
    SAML_ORGANIZATION_DISPLAY_NAMEOptional. The name that the sign-in page shows above the SAML button.
    DELETE_EXPIRED_SESSIONS_SCHEDULEJoplin Server はデフォルトで 6 時間ごとにセッションをクリアするため、SAML ユーザーは手動で再サインインする必要があります。値を空にすることでこの機能を無効化できます。

    SAML サインインのみを許可するには、LOCAL_AUTH_ENABLED=false も設定します。

  4. Joplin Server を再起動します。

結果の確認​

  1. プライベートブラウザウィンドウで https://joplin.example.com/login を開き、Login using your organisation account をクリックします。
  2. Casdoor にサインインします。Casdoor ユーザーがサインインした状態で Joplin Server のホーム画面が開きます。Joplin Server にまだ存在しないユーザーは、この最初のサインイン時に Casdoor のメールと表示名を用いて作成されます。
  3. Joplin アプリで、同期先として Joplin Server (SAML) を選択し、https://joplin.example.com を入力します。アプリはブラウザでサインイン画面を開きます。Casdoor にサインインした後、Joplin Server がコードを表示するので、アプリに入力して同期を開始します。

トラブルシューティング​

SymptomCause and fix
Joplin Server logs FAILED_TO_VERIFY_SIGNATURE: POST /api/samlUpdate Casdoor to the latest version. If it persists, download the metadata again: Joplin Server must have the certificate of the application's current Cert.
Joplin Server logs canonicalization algorithm 'http://www.w3.org/2006/12/xml-c14n11' is not supportedTurn on Enable SAML C14N10 on the application.
Joplin Server logs ERR_EXCEPTION_VALIDATE_XML, about xs:string without a namespace declarationUpdate Casdoor to the latest version. Older versions drop the xs namespace from the response when they sign it.
email must be a string or displayName must be a stringAdd the email and displayName rows to SAML attributes, with these exact names, and check that Disable SAML attributes is off.
Could not login using email "..."Joplin Server already has a local account with a password for this email, and doesn't let SAML sign in to it. Delete or rename the local account in Joplin Server.
The browser opens a Joplin Server URL that ends with [object Object]The IdP metadata has no HTTP-POST endpoint. Turn on Enable SAML POST binding, and download the metadata again with enablePostBinding=true.
Casdoor shows Issuer URI: Joplin doesn't exist in the allowed Redirect URI listAdd the entityID of sp.xml to Redirect URLs.
Casdoor shows AssertionConsumerServiceURL: ... doesn't match the SAML reply URL or the allowed Redirect URI listAdd <APP_BASE_URL>/api/saml to Redirect URLs.

関連項目​