ข้ามไปยังเนื้อหาหลัก

เริ่มต้น service ใน environment ที่ไม่เชื่อถือ

ทำตามคำแนะนำเหล่านี้หากใช้งาน IBM Cloud หรือ IBM Quantum Compute Service REST API ใน environment ที่ไม่เชื่อถือ เช่น คอมพิวเตอร์สาธารณะ

หลีกเลี่ยงการรันโค้ดบนเครื่องที่ไม่เชื่อถือหรือ cloud Python environment ภายนอกเพื่อลดความเสี่ยงด้านความปลอดภัย หากจำเป็นต้องใช้ environment ที่ไม่เชื่อถือ (เช่น คอมพิวเตอร์ที่ใช้ร่วมกันหรือสาธารณะ) ให้เปลี่ยน API key หลังจากแต่ละการใช้งานโดยการลบบน หน้า API keys และสร้างใหม่

ข้อควรระวัง

ปกป้อง API key ของคุณ! ห้ามใส่ key ในซอร์สโค้ด, Python script หรือไฟล์ notebook เมื่อแชร์โค้ดกับผู้อื่น ตรวจสอบให้แน่ใจว่า API key ไม่ได้ฝังโดยตรงใน Python script แต่ควรแชร์ script โดยไม่มี token และให้คำแนะนำสำหรับการตั้งค่าอย่างปลอดภัยแทน

ถ้าเผลอแชร์ key กับผู้อื่นหรือใส่ไว้ใน version control เช่น Git ให้เพิกถอน key ทันทีโดยทำตาม Deleting an API key บน IBM Cloud

ค้นหา access credentials

  1. ค้นหา API key (เรียกอีกชื่อว่า API token) จาก dashboard สร้าง API key แล้วคัดลอกไปเก็บในที่ปลอดภัยเพื่อใช้ยืนยันตัวตน Token จะไม่แสดงอีกครั้ง โปรดทราบว่าสามารถใช้ API key เดียวเพื่อเชื่อมต่อกับ region ใดก็ได้

  2. ไม่บังคับ: ค้นหา instance ที่ต้องการใช้จากหน้า Instances วางเมาส์เหนือ CRN คลิกไอคอนเพื่อคัดลอก แล้วบันทึกในที่ปลอดภัยเพื่อใช้ระบุ instance

ยืนยันตัวตนกับ IBM Cloud ใน environment ที่ไม่เชื่อถือ

หากต้องการเริ่มต้น service ในสถานการณ์นี้ ให้ใช้โค้ดดังนี้:

from qiskit_ibm_runtime import QiskitRuntimeService

# The credentials you enter will override any saved
# account credentials that might be available locally.
service = QiskitRuntimeService(
# Use the 44-character API_KEY you created and saved from
# the IBM Quantum Platform dashboard, and then delete
# the key on the API keys page after entering this code:
token="<your-API-key>",

# Optionally specify an instance to use
instance="<IBM Cloud CRN or instance name>"
)

ยืนยันตัวตนกับ REST API ใน environment ที่ไม่เชื่อถือ

ทำตามขั้นตอนเหล่านี้เพื่อใช้ API key โดยตรงในการยืนยันตัวตนกับ IBM Quantum Compute Service REST API โดยที่ <your_API_KEY> คือ API_KEY 44 ตัวอักษรที่สร้างและบันทึกไว้จาก IBM Quantum Platform Home dashboard

  1. ใช้ API key เพื่อสร้าง bearer token bearer token คือ credential ชั่วคราวที่หมดอายุภายในไม่เกินหนึ่งชั่วโมง หลังจาก token หมดอายุ ต้องสร้างใหม่เพื่อดำเนินการเรียก IBM Cloud หรือ service APIs อื่น ๆ ต่อ:

    curl -X POST 'https://iam.cloud.ibm.com/identity/token' \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -d 'grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=your_API_KEY'

    Copy and save the returned bearer token: "access_token": "<NEW_BEARER_TOKEN>"

  2. Authenticate requests to the IBM Quantum Compute Service REST API by including the CRN and bearer token in the request's headers.

    curl -X 'GET' \
    'https://quantum.cloud.ibm.com/api/v1/usage' \
    '-H accept: application/json' \
    '-H authorization: Bearer <BEARER_TOKEN>' \
    '-H Service-CRN: <INSTANCE_CRN>'
  3. เปลี่ยน API key ของคุณหลังการใช้งานแต่ละครั้งโดย ลบ API key ที่มีอยู่ และสร้าง API key ใหม่ในหน้าหลักของ IBM Quantum Platform

ขั้นตอนถัดไป

คำแนะนำ