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

# XUserGetTokenAndSignatureOptions

> XUserGetTokenAndSignatureOptions

# XUserGetTokenAndSignatureOptions

[XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync) 的选项。

## Syntax

```cpp theme={null}
enum class XUserGetTokenAndSignatureOptions  : uint32_t  
{  
    None = 0x00,  
    ForceRefresh = 0x01,  
    AllUsers = 0x02,  
}  
```

## Constants

| 常量           | 说明            |
| ------------ | ------------- |
| None         | 没有选项。         |
| ForceRefresh | 强制刷新。         |
| AllUsers     | 为所有用户获取令牌和签名。 |

## Remarks

[XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync) 函数使用 XUserGetTokenAndSignatureOptions 枚举参数异步检索用于 Web 请求的 xtoken 和签名。

类似地，[XUserGetTokenAndSignatureUtf16Async](/reference/system/xuser/functions/xusergettokenandsignatureutf16async) 函数使用 XUserGetTokenAndSignatureOptions 枚举参数异步检索用于 Web 请求的 Unicode xtoken 和签名。

以下示例演示了如何异步检索用户的令牌和签名。

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

## Requirements

**头文件：** XUser.h

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## See also

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

[XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync)

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

[XUserGetTokenAndSignatureUtf16Async](/reference/system/xuser/functions/xusergettokenandsignatureutf16async)


## Related topics

- [XUserGetTokenAndSignatureUtf16Async](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureutf16async.md)
- [XUserGetTokenAndSignatureUtf16ResultSize](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureutf16resultsize.md)
- [XUserGetTokenAndSignatureUtf16Result](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureutf16result.md)
- [XUserGetTokenAndSignatureAsync](/zh-CN/reference/system/xuser/functions/xusergettokenandsignatureasync.md)
- [XUser](/zh-CN/reference/system/xuser/xuser_members.md)
