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

# XUserGetTokenAndSignatureResultSize

> XUserGetTokenAndSignatureResultSize

Gets the buffer size for holding the results of a call to [XUserGetTokenAndSignatureAsync](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureasync.md).

## Syntax

```cpp theme={null}
HRESULT XUserGetTokenAndSignatureResultSize(  
         XAsyncBlock* async,  
         size_t* bufferSize  
)  
```

### Parameters

*async*   \_Inout\_\
Type: [XAsyncBlock\*](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md)

An [XAsyncBlock](https://docs.xbox.com/reference/system/xasync/structs/xasyncblock.md) for polling the call's status and retrieving call results.

*bufferSize*   \_Out\_\
Type: size\_t\*

Contains the required buffer size.

### Return value

Type: HRESULT

Returns S\_OK if successful; otherwise, returns an error code.
For a list of error codes, see [Error Codes](https://docs.xbox.com/reference/errorcodes.md).

## Remarks

To asynchronously retrieve xtokens and signatures for web requests, call [XUserGetTokenAndSignatureAsync](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureasync.md).

To retrieve the result of calling [XUserGetTokenAndSignatureAsync](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureasync.md), call [XUserGetTokenAndSignatureResult](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureresult.md).

The following example demonstrates how to asynchronously retrieve the token and signature of a user.

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

**Header:** XUser.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, Steam Deck, XBOX One family consoles and XBOX Series consoles

## See also

[XUser](https://docs.xbox.com/reference/system/xuser/xuser_members.md)

[XUserGetTokenAndSignatureAsync](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureasync.md)

[XUserGetTokenAndSignatureResult](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureresult.md)


## Related topics

- [XUserGetTokenAndSignatureResult](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureresult.md)
- [XUserGetTokenAndSignatureAsync](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureasync.md)
- [XUser (API contents)](https://docs.xbox.com/reference/system/xuser/xuser_members.md)
- [Using C# wrappers for GDK APIs in your Unity project](https://docs.xbox.com/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XUserGetTokenAndSignatureUtf16ResultSize](https://docs.xbox.com/reference/system/xuser/functions/xusergettokenandsignatureutf16resultsize.md)
