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

# XUserGetTokenAndSignatureResult

> XUserGetTokenAndSignatureResult

# XUserGetTokenAndSignatureResult

Gets the result of a call to [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync).

## Syntax

```cpp theme={null}
HRESULT XUserGetTokenAndSignatureResult(  
         XAsyncBlock* async,  
         size_t bufferSize,  
         void* buffer,  
         XUserGetTokenAndSignatureData** ptrToBuffer,  
         size_t* bufferUsed  
)  
```

### Parameters

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

An [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) for polling the call's status and retrieving call results.

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

The size of the buffer in the *buffer* parameter.

*buffer*   \_Out\_writes\_bytes\_to\_(bufferSize,*bufferUsed)\
Type: void*

Contains the results of the call to [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync).

*ptrToBuffer*   \_Outptr\_\
Type: [XUserGetTokenAndSignatureData\*\*](/reference/system/xuser/structs/xusergettokenandsignaturedata)

On return, *prtToBuffer* points to the buffer you specify in the *buffer* parameter. The parameter provides a typed pointer to *buffer* and doesn't need to be freed independently.

*bufferUsed*   \_Out\_opt\_\
Type: size\_t\*

The number of bytes written in the *buffer* parameter.

### Return value

Type: HRESULT

Returns S\_OK if successful; otherwise, returns an error code.

| HRESULT    | Message ID                               | Description                                                                     |
| ---------- | ---------------------------------------- | ------------------------------------------------------------------------------- |
| 0x80072EE7 | WININET\_E\_NAME\_NOT\_RESOLVED          | The server name or address couldn't be resolved.                                |
| 0x80072EFD | WININET\_E\_CANNOT\_CONNECT              | A connection with the server couldn't be established.                           |
| 0x80072EFE | WININET\_E\_CONNECTION\_ABORTED          | The connection with the server was terminated abnormally.                       |
| 0x80072F8F | WININET\_E\_DECODING\_FAILED             | Content decoding failed.                                                        |
| 0x8015DC01 | XO\_E\_SYSTEM\_UPDATE\_REQUIRED          | System must be updated before being allowed to grant X-tokens.                  |
| 0x8015DC0B | XO\_E\_ACCOUNT\_COUNTRY\_NOT\_AUTHORIZED | Title trying to be used in a country/region it isn't authorized for.            |
| 0x8015DBFF | XO\_E\_GAME\_USAGE\_BY\_USER\_EXCEEDED   | User exceeded their allotted time allowed to play the game (parental controls). |
| 0x80860006 | ONL\_E\_FORCESIGNIN                      | To help protect your Online ID account, you must sign in again.                 |
| 0x87DD0006 | AM\_E\_XSTS\_UNEXPECTED                  | Unknown error occurred.                                                         |
| 0x87DD0013 | AM\_E\_USER\_NOT\_FOUND                  | User object is no longer signed in or is unknown.                               |
| 0x87DD0019 | AM\_E\_XSTS\_TIMEOUT                     | Timeout limit hit when trying to retrieve the X-token.                          |
| 0x87DD0022 | AM\_E\_XTITLE\_TIMEOUT                   |                                                                                 |
| 0x87DD0033 | AM\_E\_XSTS\_SERVICE\_UNAVAILABLE        | The X token service is unable to be reached.                                    |

For a list of other error codes, see [Error Codes](/reference/errorcodes).

## Remarks

To asynchronously retrieve X-tokens and signatures for web requests, call [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync).

To retrieve the required buffer size to hold the results of calling [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync), call [XUserGetTokenAndSignatureResultSize](/reference/system/xuser/functions/xusergettokenandsignatureresultsize).

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](/reference/system/xuser/xuser_members)

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

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


## Related topics

- [XUserGetTokenAndSignatureResultSize](/reference/system/xuser/functions/xusergettokenandsignatureresultsize.md)
- [XUserGetTokenAndSignatureData](/reference/system/xuser/structs/xusergettokenandsignaturedata.md)
- [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync.md)
- [XUserGetTokenAndSignatureOptions](/reference/system/xuser/enums/xusergettokenandsignatureoptions.md)
- [XUserGetTokenAndSignatureHttpHeader](/reference/system/xuser/structs/xusergettokenandsignaturehttpheader.md)
