AuthCredential - スコープ付き

  • リリースバージョン: Yokohama
  • 更新日 2025年01月30日
  • 所要時間:6分
  • AuthCredential() API は、REST 要求の資格情報を構築できるようにするメソッドを提供します。

    次の順序でこれらの API を使用して、送信署名要求を生成します。
    1. HttpRequestData:API 要求を構築します。
    2. AuthCredential:資格情報オブジェクトを作成するか、既存のオブジェクトを更新します。資格情報を使用して、RequestAuthAPI クラスで要求に署名します。
    3. RequestAuthAPI:要求に署名し、HttpRequestAuthedData オブジェクトを返します。
    4. HttpRequestAuthedData:署名された要求に関する情報を取得します。
    5. GlideHTTPRequest:署名された要求を送信します。

    これらの API を使用する前に、要求に署名し、要求の認証に使用される認証情報に関連付ける 認証アルゴリズムを構成する 必要があります。

    空の AuthCredential オブジェクトを作成するか、既存の AuthCredential オブジェクトをインスタンス化するか、または StandardCredentialsProvider クラスを使用し、資格情報 [discovery_credentials] テーブルの資格情報レコードを使用して AuthCredential オブジェクトをインスタンス化することができます。空の AuthCredential オブジェクトを作成した場合は、setAttribute() メソッドを使用してオブジェクトにプロパティを追加します。

    次の例は、 StandardCredentialsProvider を使用して AuthCredential をインスタンス化する方法を示しています。
    // Return an AuthCredential object using a Credential sys_id
    var credential = new sn_cc.StandardCredentialsProvider().getAuthCredentialByID("5b61c16f73533300f662cff8faf6a74b");

    sn_auth 名前空間識別子を持つスコープ対象スクリプトで AuthCredential API を使用します。

    AuthCredential - AuthCredential(オブジェクト authCredential)

    新しい AuthCredential オブジェクトをインスタンス化するか、既存のものを変更します。

    空の AuthCredential オブジェクトを作成するか、既存の AuthCredential オブジェクトをインスタンス化するか、または StandardCredentialsProvider クラスを使用し、資格情報 [discovery_credentials] テーブルの資格情報レコードを使用して AuthCredential オブジェクトをインスタンス化することができます。空の AuthCredential オブジェクトを作成した場合は、setAttribute() メソッドを使用してオブジェクトにプロパティを追加します。

    表 : 1. パラメーター
    名前 タイプ 説明
    authCredential オブジェクト オプション。既存の AuthCredential オブジェクトを更新するには、このパラメーターを含めます。

    AuthCredential - getAttribute(文字列 key)

    AuthCredential 属性の値を返します。

    表 : 2. パラメーター
    名前 タイプ 説明
    key 文字列 値を返す属性のキーです。

    空の AuthCredential オブジェクトを作成した場合は、 setAttribute() メソッドを使用してオブジェクトにプロパティを追加する必要があります。

    資格情報レコードを使用して AuthCredential オブジェクトをインスタンス化した場合は、資格情報 [discovery_credentials] テーブルからフィールド名を渡して値にアクセスします。

    表 : 3. 返される内容
    タイプ 説明
    なし
    // Define the HttpRequestData object
    var endpoint= "https://third-party-endpoint";
    var httpRequestData = new sn_auth.HttpRequestData();
    httpRequestData.setEndpoint(endpoint);
    httpRequestData.setService('s3');
    httpRequestData.setRegion('us-east-1');
    httpRequestData.setHttpMethod("PUT");
    var content = "Action=SendMessage&MessageBody=This is a test message";
    httpRequestData.setContent(content);
    httpRequestData.addHeader('x-amz-acl', 'public-read' );
     
    // Get AuthCredential object and set an attribute
    var credential = new sn_auth.AuthCredential();
    credential.setAttribute("user_name", "admin");
     
    // Sign the request and return an AuthCredential attribute value
    var signingAPI = new sn_auth.RequestAuthAPI(httpRequestData, credential);
    var signingCredential = signingAPI.getAuthCredential();
    name = signingCredential.getAttribute("name");

    AuthCredential - setAttribute(文字列 key, 文字列 value)

    AuthCredential オブジェクトの属性を設定します。

    表 : 4. パラメーター
    名前 タイプ 説明
    key 文字列 設定する属性の名前です。空の AuthCredential オブジェクトを作成した場合、このメソッドを使用してオブジェクトにプロパティを追加する必要があります。資格情報レコードを使用して AuthCredential オブジェクトをインスタンス化した場合は、資格情報 [discovery_credentials] テーブルからフィールド資格名を渡して値を設定します。
    value 文字列 属性の値です。
    表 : 5. 返される内容
    タイプ 説明
    なし
    // Define the HttpRequestData object
    var endpoint= "https://third-party-endpoint";
    var httpRequestData = new sn_auth.HttpRequestData();
    httpRequestData.setEndpoint(endpoint);
    httpRequestData.setService('s3');
    httpRequestData.setRegion('us-east-1');
    httpRequestData.setHttpMethod("PUT");
    var content = "Action=SendMessage&MessageBody=This is a test message";
    httpRequestData.setContent(content);
    httpRequestData.addHeader('x-amz-acl' , 'public-read' );
     
    // Get AuthCredential object and set an attribute
    var credential = new sn_auth.AuthCredential();
    credential.setAttribute("user_name", "admin");