Trying to get profile image of logged in user then save it on the server.

This code is from Startup.Auth.cs

 AuthorizationCodeReceived = async (context) =>
                           {
                               var code = context.Code;
                               ClientCredential credential = new ClientCredential(clientId, appKey);
                               string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                               string userObjectID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
                               AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID));  
                               AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
                               code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
                               AuthenticationResult authenticationResult = await authContext.AcquireTokenSilentAsync(graphResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
                               Uri servicePointUri = new Uri(graphResourceId);
                               Uri serviceRoot = new Uri(servicePointUri, tenantId);
                               ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async () => await Task.FromResult(result.AccessToken));
                               var res = await activeDirectoryClient.Users
                               .Where(u => u.ObjectId.Equals(userObjectID))
                               .ExecuteAsync();
                               IUser user = res.CurrentPage.ToList().First();

                               var image = await user.ThumbnailPhoto.DownloadAsync();


                           }

await user.ThumbnailPhoto.DownloadAsync() throws this error

{"odata.error":{"code":"Request_ResourceNotFound","message":{"lang":"en","value":"Resource 'thumbnailPhoto' does not exist or one of its queried reference-property objects are not present."}}}

Related posts

Recent Viewed