> For the complete documentation index, see [llms.txt](https://manual.dxable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.dxable.com/1password/manage-items-using-1password-sdks.md).

# 1Password SDKを使用してシークレットをロードする

### 1Password SDKを使用してシークレットをロードする <a href="#r9wibb4h1aru" id="r9wibb4h1aru"></a>

[1Password SDK を使うと、シークレット参照](https://developer.1password.com/docs/cli/secret-reference-syntax/)を使用してシークレットをコードに安全に読み込むことができます。始める前に、1Password SDK の[使用を開始するための手順に従ってください。](https://developer.1password.com/docs/sdks#get-started)

[サポートされているフィールド タイプ](https://developer.1password.com/docs/sdks/concepts/#supported-field-types)からシークレットを取得できます。[otp属性パラメータを](https://developer.1password.com/docs/sdks/concepts/#supported-query-parameters)使用してワンタイム パスワードを取得することもできます。

有効なシークレット参照では次の構文を使う必要があります。

op\://\<vault>/\<item>/\[section/]\<field>

ワンタイム パスワードを取得するには、?attribute=otp1Password のワンタイム パスワード フィールドを指すシークレット参照にクエリ パラメータを追加します。

op\://\<vault>/\<item>/\[section/]one-time password?attribute=otp

ヒント

プロジェクトですぐに複製してテストできるサンプル コードについては、 1Password [Go](https://github.com/1Password/onepassword-sdk-go/tree/main/example)、[JavaScript](https://github.com/1Password/onepassword-sdk-js/tree/main/examples)、または[Python](https://github.com/1Password/onepassword-sdk-python/tree/main/example) SDK GitHub リポジトリの examples フォルダーを参照してください。

### 1Passwordからシークレットをロードする <a href="#lgx37bx2vp12" id="lgx37bx2vp12"></a>

例のプレースホルダー[シークレット参照を](https://developer.1password.com/docs/sdks/concepts#secret-references)、1Password アカウントでシークレットがSaveされる保管庫、アイテム、セクション (該当する場合)、およびフィールドを指定するシークレット参照 URI に置き換えます。

同じ名前を共有する複数の保管庫、アイテム、またはフィールドがある場合は、シークレット参照の名前の代わりに[一意の識別子を使用します。](https://developer.1password.com/docs/sdks/concepts#unique-identifiers)

* **Go**

// Retrieves a secret from 1Password.

// Takes a secret reference as input and returns the secret to which it points.

secret, err := client.Secrets.Resolve(context.Background(), fmt.Sprintf("op\://%s/%s/%s", vaultID, itemID, fieldID))

if err != nil {

panic(err)

}

fmt.Println(secret)

* **JavaScript**

シークレットを取得してその値を印刷するには:

// Fetches a secret.

const secret = await client.secrets.resolve("op\://vault/item/field");

console.log(secret);

* **Python**

シークレットを取得してその値を印刷するには:

\# Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points.

value = await client.secrets.resolve("op\://vault/item/field")

print(value)

このresolve関数はシークレット参照を解決し、参照する 1Password フィールドの値を返します。その後、この値をコード内で使用して、別のサービスに認証することができます。

### [さらに](https://developer.1password.com/docs/sdks/load-secrets/#learn-more)詳しく <a href="#id-2rbn4srug0bf" id="id-2rbn4srug0bf"></a>

* [秘密参照構文](https://developer.1password.com/docs/cli/secret-reference-syntax/)
* [1Password SDKを使用してアイテムを管理する](https://developer.1password.com/docs/sdks/manage-items/)
* [1Password SDKを使用して保管庫とアイテムを一覧表示する](https://developer.1password.com/docs/sdks/list-vaults-items/)
