暗号化APIKeyの要件
ibm-appconfiguration-js-client-sdk と'ibm-appconfiguration-react-client-sdk では、セキュリティ強化のため、プレーンテキストのAPIKeyではなく、暗号化されたClient SDK APIKey を提供する必要があります。 これにより、ブラウザでウェブページを検査する際にAPIKeyが公開されるのを防ぐことができます。
最大限のセキュリティを提供するため、暗号化処理中にランダムなノンスを利用する。 その結果、APIKeyを暗号化するたびに、暗号化された値は異なりますが、認証時に復号化されたときの基礎となるプレーンテキストは同じままです。
暗号化クライアントSDK APIキーの生成と使用手順
- プレーンAPIKeyを取得する:
- IBM CloudダッシュボードのApp Configurationインスタンスの Service Credentials セクションに移動します。
Client SDKロールのAPIKeyを生成し、サービスのクレデンシャルからapikeyをコピーします。
- APIKeyを暗号化する:
-
プレーンなAPIKeyを暗号化するには、以下のAPIエンドポイントを使用します
POST /apprapp/feature/v1/instances/<guid>/encrypt例:
https://eu-gb.apprapp.cloud.ibm.com/apprapp/feature/v1/instances/720f9034-c990-4305-96d6-4f65ffacef2c/encrypt -
リクエストの本文に、以下のようにプレーンなAPIKeyを含める:
{ "client_sdk_apikey": "your_plain_apikey" } -
応答にはAES-256で暗号化されたAPIKeyが含まれます。
-
- コードを更新する
Javascript SDK: 初期化コードを更新する:
-
アプリケーションでのプレーンAPIKeyの使用を暗号化APIKeyに置き換える。 以下は、暗号化されたAPIKeyを使用してSDKを初期化する方法の最新の例です: js const region =AppConfiguration.REGION_US_SOUTH; // 地域を指定する。 const guid = '
'; // サービス資格情報のインスタンスID const apikey = '<encrypted_apikey>'; // 暗号化されたAPIKeyを使用する。 const collectionId = 'airlines-webapp'; // Your collection ID const environmentId = 'dev'; // Your environment ID const appConfigClient = AppConfiguration.getInstance(); async function initialiseAppConfig() { appConfigClient.init(region, guid, apikey); // Initialize with encrypted APIKey await appConfigClient.setContext(collectionId, environmentId); } try { await initialiseAppConfig(); console.log("App configuration SDK initialized successfully"); } catch (e) { console.error("Failed to initialize app configuration SDK", e); } ```
React SDK: AppConfigProvider コードを更新してください:
-
アプリケーションでのプレーンAPIKeyの使用を暗号化APIKeyに置き換える。 以下は、暗号化されたAPIKeyを使用してSDKを初期化する方法の最新の例です: js インポート{ withAppConfigProvider }from 'ibm-appconfiguration-react-client-sdk';
(async () => { const AppConfigProvider = await withAppConfigProvider({ region: 'us-south', // Specify your region guid: '<guid>', // Instance ID from Service Credentials apikey: '<encrypted_apikey>', // Use the encrypted APIKey collectionId: 'airlines-webapp', // Your collection ID environmentId: 'dev' // Your environment ID }) ReactDOM.render( <AppConfigProvider> <YourApp /> </AppConfigProvider>, document.getElementById('root') ); })(); ```
既存ユーザー更新が必要
すでにプレーンなAPIKeyを使用している場合は、前の手順に従って暗号化されたAPIKeyを生成し、使用するようにアプリケーションを更新してください。