> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XUserGetTokenAndSignatureAsync

> XUserGetTokenAndSignatureAsync

# XUserGetTokenAndSignatureAsync

対象 URL への HTTPS 呼び出しの認可に必要な X-token と Signature を非同期に取得する API です。タイトルの [パートナー センターのシングル サインオン ページ](/services/xbox-services/fundamentals/s2s-auth-calls/custom-service-config/single-sign-on/live-single-sign-on) で対象 URL に紐付けられている証明書利用者 (Relying Party) が存在する場合、X-token と Signature を返します。要求を行う前に、[API の Results バージョン](/reference/system/xuser/functions/xusergettokenandsignatureresult) から取得した X-token と Signature の値を HTTPS 呼び出しの Authorization ヘッダーと Signature ヘッダーに追加してください。

## 構文

```cpp theme={null}
HRESULT XUserGetTokenAndSignatureAsync(  
         XUserHandle user,  
         XUserGetTokenAndSignatureOptions options,  
         const char* method,  
         const char* url,  
         size_t headerCount,  
         const XUserGetTokenAndSignatureHttpHeader* headers,  
         size_t bodySize,  
         const void* bodyBuffer,  
         XAsyncBlock* async  
)  
```

### パラメーター

*user*   \_In\_\
Type: XUserHandle

Web 要求の対象ユーザーへのハンドルです。

*options*   \_In\_\
Type: [XUserGetTokenAndSignatureOptions](/reference/system/xuser/enums/xusergettokenandsignatureoptions)

ユーザー トークンと署名を取得するためのオプションです。

*method*   \_In\_z\_\
Type: char\*

Web 要求のメソッド タイプです。

*url*   \_In\_z\_\
Type: char\*

HTTPS 要求の対象 URL です。HTTPS 要求には完全な URL 文字列を使用してください。URL を省略しないでください。

*headerCount*   \_In\_\
Type: size\_t

*headers* パラメーター内のヘッダーの数です。

*headers*   \_In\_reads\_opt\_(headerCount)\
Type: [XUserGetTokenAndSignatureHttpHeader\*](/reference/system/xuser/structs/xusergettokenandsignaturehttpheader)

Web 要求のヘッダーです。

*bodySize*   \_In\_\
Type: size\_t

*bodyBuffer* パラメーターのバッファーのサイズです。

*bodyBuffer*   \_In\_reads\_bytes\_opt\_(bodySize)\
Type: void\*

Web 要求の本文が格納されるバッファーです。

*async*   \_Inout\_\
Type: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

呼び出しの状態のポーリングと呼び出し結果の取得に使用する [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) です。

### 戻り値

Type: HRESULT

成功した場合は S\_OK を返します。それ以外の場合はエラー コードを返します。
エラー コードの一覧については、[エラー コード](/reference/errorcodes) を参照してください。

## 解説

XUserGetTokenAndSignatureAsync の呼び出し結果を取得するには、[XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult) を呼び出します。

[XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync) の呼び出し結果を保持するために必要なバッファー サイズを取得するには、[XUserGetTokenAndSignatureResultSize](/reference/system/xuser/functions/xusergettokenandsignatureresultsize) を呼び出します。

以下の例は、ユーザーのトークンと署名を非同期に取得する方法を示しています。

```cpp theme={null}
HRESULT RequestTokenComplete(XAsyncBlock* abResult)
{
    size_t bufferSize;
    RETURN_IF_FAILED(XUserGetTokenAndSignatureResultSize(abResult, &bufferSize));

    std::vector<uint8_t> buffer(bufferSize);
    XUserGetTokenAndSignatureData* data;
    if (SUCCEEDED_LOG(XUserGetTokenAndSignatureResult(abResult, buffer.size(), buffer.data(), &data, nullptr /*bufferUsed*/)))
    {
        appLog.AddLog("Token: %s\n", data->token);
        if (data->signature != nullptr)
        {    
            appLog.AddLog("Signature: %s\n", data->signature);
        }
    }

    return S_OK;
}

HRESULT RequestTokenAsync(
    XTaskQueueHandle queue,
    const char* url,
    bool forceRefresh)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = queue;
    asyncBlock->context = this;
    asyncBlock->callback = [](XAsyncBlock* ab)
    {
        LOG_IF_FAILED(static_cast<User*>(ab->context)->RequestTokenComplete(ab));
        delete ab;
    };


    XUserGetTokenAndSignatureOptions options = XUserGetTokenAndSignatureOptions::None;

    if (forceRefresh)
    {
        WI_SET_FLAG(options, XUserGetTokenAndSignatureOptions::ForceRefresh);
    }

    static const XUserGetTokenAndSignatureHttpHeader headers[] =
    {
        { "Accept", "application/json"},
        { "Why", "Because"},
    };

    if (SUCCEEDED_LOG(XUserGetTokenAndSignatureAsync(
        _handle.get(),
        options,
        "GET",
        url,
        ARRAYSIZE(headers),
        headers,
        0,
        nullptr,
        asyncBlock.get())))
    {
        // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* since the callback will take over ownership.
        // If the call fails, the std::unique_ptr will keep ownership and delete the XAsyncBlock*
        asyncBlock.release();
    }

    return S_OK;
}
```

## 要件

**ヘッダー:** XUser.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、Steam Deck、XBOX One ファミリ本体および XBOX Series 本体

## 関連項目

[XUser](/reference/system/xuser/xuser_members)

[XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult)

[XUserGetTokenAndSignatureResultSize](/reference/system/xuser/functions/xusergettokenandsignatureresultsize)


## Related topics

- [XUserGetTokenAndSignatureOptions](/ja-jp/reference/system/xuser/enums/xusergettokenandsignatureoptions.md)
- [XUserGetTokenAndSignatureData](/ja-jp/reference/system/xuser/structs/xusergettokenandsignaturedata.md)
- [XUserGetTokenAndSignatureResult](/ja-jp/reference/system/xuser/functions/xusergettokenandsignatureresult.md)
- [XUserGetTokenAndSignatureResultSize](/ja-jp/reference/system/xuser/functions/xusergettokenandsignatureresultsize.md)
- [XUserGetTokenAndSignatureHttpHeader](/ja-jp/reference/system/xuser/structs/xusergettokenandsignaturehttpheader.md)
