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

Specifies the xtokens and signatures that we retrieve for web requests.

## Syntax

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

### Members

*tokenSize*\
Type: size\_t

The size in bytes of the buffer in the **token** property.

*signatureSize*\
Type: size\_t

The size in bytes of the buffer in the **signature** property.

*token*\
Type: const char\*

A buffer that contains the retrieved token.

*signature*\
Type: const char\*

A buffer that contains the retrieved signature.

## Remarks

To retrieve the result of a call to [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync), call the [XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult) function.

The [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync) function asynchronously retrieves xtokens and signatures for web requests.

The [XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult) function uses a double pointer to an XUserGetTokenAndSignatureData structure as an argument.

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

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

## See also

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

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

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


## Related topics

- [XUserGetTokenAndSignatureResult](/reference/system/xuser/functions/xusergettokenandsignatureresult.md)
- [XUser](/reference/system/xuser/xuser_members.md)
- [XUserGetTokenAndSignatureUtf16Data](/reference/system/xuser/structs/xusergettokenandsignatureutf16data.md)
- [XUserGetTokenAndSignatureUtf16Result](/reference/system/xuser/functions/xusergettokenandsignatureutf16result.md)
- [XUserGetTokenAndSignatureOptions](/reference/system/xuser/enums/xusergettokenandsignatureoptions.md)
