XUserGetTokenAndSignatureData
指定我们为 Web 请求检索的 xtoken 和签名。
语法
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 的调用结果,请调用 XUserGetTokenAndSignatureResult 函数。
XUserGetTokenAndSignatureAsync 函数异步检索 Web 请求的 xtoken 和签名。
XUserGetTokenAndSignatureResult 函数使用指向 XUserGetTokenAndSignatureData 结构的双指针作为参数。
下面的示例演示如何异步检索用户的标记和签名。
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 主机