> ## 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.

# XUserGetTokenAndSignatureData

> XUserGetTokenAndSignatureData

# XUserGetTokenAndSignatureData

指定為 Web 要求擷取的 xtoken 和簽章。

## 語法

```cpp theme={null}
typedef struct XUserGetTokenAndSignatureData {  
    size_t tokenSize;  
    size_t signatureSize;  
    const char* token;  
    const char* signature;  
} XUserGetTokenAndSignatureData  
```

### 成員

*tokenSize*\
類型：size\_t

**token** 屬性中緩衝區的大小 (以位元組為單位)。

*signatureSize*\
類型：size\_t

**signature** 屬性中緩衝區的大小 (以位元組為單位)。

*token*\
類型：const char\*

包含所擷取權杖的緩衝區。

*signature*\
類型：const char\*

包含所擷取簽章的緩衝區。

## 備註

若要擷取 [XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync) 呼叫的結果，請呼叫 [XUserGetTokenAndSignatureResult](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureresult) 函式。

[XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync) 函式會以非同步方式擷取 Web 要求的 xtoken 和簽章。

[XUserGetTokenAndSignatureResult](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureresult) 函式會使用 XUserGetTokenAndSignatureData 結構的雙重指標作為引數。

下列範例示範如何以非同步方式擷取使用者的權杖和簽章。

```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

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XUser](/zh-TW/reference/system/xuser/xuser_members)

[XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync)

[XUserGetTokenAndSignatureResult](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureresult)


## Related topics

- [XUserGetTokenAndSignatureData](/reference/system/xuser/structs/xusergettokenandsignaturedata.md)
- [XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult.md)
- [XUser](/reference/system/xuser/xuser_members.md)
