| 909 | } |
| 910 | |
| 911 | CesiumAsync::Future<Response<Token>> Connection::createToken( |
| 912 | const std::string& name, |
| 913 | const std::vector<std::string>& scopes, |
| 914 | const std::optional<std::vector<int64_t>>& assetIds, |
| 915 | const std::optional<std::vector<std::string>>& allowedUrls) const { |
| 916 | return this->ensureValidToken().thenImmediately( |
| 917 | [pAssetAccessor = this->_pAssetAccessor, |
| 918 | asyncSystem = this->_asyncSystem, |
| 919 | apiUrl = this->_apiUrl, |
| 920 | name, |
| 921 | scopes, |
| 922 | assetIds, |
| 923 | allowedUrls](Result<std::string>&& result) { |
| 924 | if (!result.value) { |
| 925 | return asyncSystem.createResolvedFuture( |
| 926 | createNoValidTokenResponse<Token>(std::move(result))); |
| 927 | } |
| 928 | |
| 929 | rapidjson::StringBuffer tokenBuffer; |
| 930 | rapidjson::Writer<rapidjson::StringBuffer> writer(tokenBuffer); |
| 931 | |
| 932 | writer.StartObject(); |
| 933 | |
| 934 | writer.Key("name"); |
| 935 | writer.String(name.c_str(), rapidjson::SizeType(name.size())); |
| 936 | |
| 937 | writer.Key("scopes"); |
| 938 | writer.StartArray(); |
| 939 | for (auto& scope : scopes) { |
| 940 | writer.String(scope.c_str(), rapidjson::SizeType(scope.size())); |
| 941 | } |
| 942 | writer.EndArray(); |
| 943 | |
| 944 | writer.Key("assetIds"); |
| 945 | if (assetIds) { |
| 946 | writer.StartArray(); |
| 947 | for (auto asset : assetIds.value()) { |
| 948 | writer.Int64(asset); |
| 949 | } |
| 950 | writer.EndArray(); |
| 951 | } else { |
| 952 | writer.Null(); |
| 953 | } |
| 954 | |
| 955 | writer.Key("allowedUrls"); |
| 956 | if (allowedUrls) { |
| 957 | writer.StartArray(); |
| 958 | for (auto& allowedUrl : allowedUrls.value()) { |
| 959 | writer.String( |
| 960 | allowedUrl.c_str(), |
| 961 | rapidjson::SizeType(allowedUrl.size())); |
| 962 | } |
| 963 | writer.EndArray(); |
| 964 | } else { |
| 965 | writer.Null(); |
| 966 | } |
| 967 | |
| 968 | writer.EndObject(); |
nothing calls this directly
no test coverage detected