| 231 | } // namespace |
| 232 | |
| 233 | CesiumAsync::Future<Response<Profile>> Connection::me() const { |
| 234 | // /v1/me endpoint doesn't exist when ion is running in single user mode |
| 235 | if (this->_appData.authenticationMode == AuthenticationMode::SingleUser) { |
| 236 | Profile profile; |
| 237 | profile.id = 0; |
| 238 | profile.username = "ion-user"; |
| 239 | profile.storage = ProfileStorage{ |
| 240 | 0, |
| 241 | std::numeric_limits<int64_t>::max(), |
| 242 | std::numeric_limits<int64_t>::max()}; |
| 243 | profile.email = "none@example.com"; |
| 244 | profile.emailVerified = true; |
| 245 | profile.scopes = { |
| 246 | "assets:read", |
| 247 | "assets:list", |
| 248 | "assets:write", |
| 249 | "profile:read", |
| 250 | "tokens:read", |
| 251 | "tokens:write"}; |
| 252 | profile.avatar = "https://www.gravatar.com/avatar/" |
| 253 | "4f14cc6c584f41d89ef1d34c8986ebfb.jpg?d=mp"; |
| 254 | return this->_asyncSystem.createResolvedFuture<Response<Profile>>( |
| 255 | Response<Profile>{ |
| 256 | std::move(profile), |
| 257 | 200, |
| 258 | std::string(), |
| 259 | std::string()}); |
| 260 | } |
| 261 | |
| 262 | const std::string url = CesiumUtility::Uri::resolve(this->_apiUrl, "v1/me"); |
| 263 | |
| 264 | return this->ensureValidToken().thenImmediately( |
| 265 | [pAssetAccessor = this->_pAssetAccessor, |
| 266 | asyncSystem = this->_asyncSystem, |
| 267 | url](Result<std::string>&& result) { |
| 268 | if (!result.value) { |
| 269 | return asyncSystem.createResolvedFuture( |
| 270 | createNoValidTokenResponse<Profile>(std::move(result))); |
| 271 | } |
| 272 | |
| 273 | return pAssetAccessor |
| 274 | ->get( |
| 275 | asyncSystem, |
| 276 | url, |
| 277 | {{"Accept", "application/json"}, |
| 278 | {"Authorization", *result.value}}) |
| 279 | .thenImmediately( |
| 280 | [](std::shared_ptr<CesiumAsync::IAssetRequest>&& pRequest) { |
| 281 | const IAssetResponse* pResponse = pRequest->response(); |
| 282 | if (!pResponse) { |
| 283 | return createEmptyResponse<Profile>(); |
| 284 | } |
| 285 | |
| 286 | if (pResponse->statusCode() < 200 || |
| 287 | pResponse->statusCode() >= 300) { |
| 288 | return createErrorResponse<Profile>(pResponse); |
| 289 | } |
| 290 |
no test coverage detected