OML Servicesユーザーの認可

Oracle Machine Learning ServicesのREST APIでは、トークンを使用してOracle Machine Learning Servicesユーザーを認証します。

Oracle Machine Learning RESTリソースにはHTTP経由でアクセスするため、認証のために次の情報を指定する必要があります。
  • Oracle Machine Learning Servicesアカウントのユーザー名とパスワード。
  • アクセス・トークン。

REST APIを使用してOracle Machine Learning Servicesにアクセスするには、アクセス・トークンを指定する必要があります。アクセス・トークンを認証および取得するには、-dオプションを指定したcURLを使用して、Oracle Machine Learning User Management Cloud Service RESTエンドポイント/oauth2/v1/tokenに対してOracle Machine Learning Servicesアカウントのユーザー名とパスワードを渡します。

アクセス・トークンの存続期間は1時間で、有効期限が切れる前にリフレッシュできます。

  • トークンは最大8時間リフレッシュできます。

  • トークンは失効にできますが、失効したトークンはリフレッシュできません。

  • 各トークンは複数回使用できます。

  • トークンは、データベース資格証明を使用して認証するユーザーに関連付けられます。

ノート:

トークン化システムに問題がある場合は、オラクル社カスタマ・サポートに連絡してください。

ユーザーの認可

ユーザーを認可するには、最初に資格証明をBearerトークンと交換する必要があります。

  1. 次の資格証明を指定してOMLサービスに接続します:
    export omlservice=https://<oml-cloud-service-location-url>.oraclecloudapps.com 
    export username=USERNAME
    export password=PASSWORD
    説明:
    • oml-cloud-service-location-urlは、テナンシIDおよびデータベース名を含むOracle Machine Learningユーザー管理クラウド・サービスのインスタンスURLのRESTサーバー部分を含むURLです。URLは、Oracle Autonomous Databaseインスタンスのサービス・コンソールの「開発」タブから取得できます。

    • USERNAMEはOMLユーザー名

    • PASSWORDはOMLユーザー・パスワード

  2. 次のcURLコマンドを実行して、アクセス・トークンを生成します。
    curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' 
    -d '{"grant_type":"password", "username":"'${username}'", "password":"'${password}'"}' 
    "<oml-cloud-service-location-url>/omlusers/api/oauth2/v1/token"
    アクセス・トークンが生成され、表示されます。
    {"accessToken":"eyJhbGci....6zIw==","expiresIn":3600,"tokenType":"Bearer"}
  3. 後続のリクエストに引渡しできるように、トークンをエクスポートして変数に保存します。コマンドexport token=を使用して、トークンをエクスポートして保存します。
    export token='eyJhbGci....6zIw=='

    ノート:

    エクスポートの際は、トークンを一重引用符で囲む必要があります。

トークンのリフレッシュ

  1. トークンをリフレッシュするには、次のcURLコマンドを実行します。
    curl -i -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer ${token}" 
    -d '{"grant_type":"refresh_token", "refresh_token":"'${token}'"}' 
    "<oml-cloud-service-location-url>/omlusers/api/oauth2/v1/token"

    ノート:

    最大8回までトークンをリフレッシュできます。
    このコマンドは、トークンが正常にリフレッシュされると、次の情報を返します。
    HTTP/1.1 100 Continue
    
    HTTP/1.1 200 OK
    Date: Mon, 09 Nov 2021 22:18:41 GMT
    Content-Type: application/json
    Content-Length: 1106
    Connection: keep-alive
    Cache-Control: no-cache, no-store, must-revalidate
    Pragma: no-cache
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1;mode=block
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Content-Type-Options: nosniff
    
    {"accessToken":"eyJhbGci.....w==","expiresIn":3600}

トークンの失効

  1. トークンを失効させるには、次のcURLコマンドを実行します。
    curl -i -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' 
    --header "Authorization: Bearer ${token}" "<oml-cloud-service-location-url>/omlusers/api/oauth2/v1/token/revoke"
    このコマンドは、トークンが正常に失効されると、次の情報を返します。
    HTTP/1.1 200 OK
    Date: Mon, 09 Nov 2021 22:20:20 GMT
    Content-Type: application/json
    Content-Length: 15
    Connection: keep-alive
    Cache-Control: no-cache, no-store, must-revalidate
    Pragma: no-cache
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1;mode=block
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Content-Type-Options: nosniff
    
    {"status":"ok"}