A função XUserGetTokenAndSignatureAsync usa um argumento de enumeração XUserGetTokenAndSignatureOptions para recuperar de forma assíncrona xtokens e assinaturas para solicitações da Web.Da mesma forma, a função XUserGetTokenAndSignatureUtf16Async usa um argumento de enumeração XUserGetTokenAndSignatureOptions para recuperar de forma assíncrona xtokens e assinaturas Unicode para solicitações da Web.O exemplo a seguir demonstra como recuperar de forma assíncrona o token e a assinatura de um usuário.
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;}