Esempio n. 1
0
 public string CreateMicrosoftPhotoUrl(string accessToken, string savePhotoSize = null)
 {
     try
     {
         using var imageStream = MicrosoftGraphAuthProvider.PhotoUrl(savePhotoSize)
                                 .GetStreamFromUrl(requestFilter: req => req.AddBearerToken(accessToken));
         var base64 = Convert.ToBase64String(imageStream.ReadFully());
         return("data:image/jpg;base64," + base64);
     }
     catch (Exception ex)
     {
         Log.Warn($"Could not retrieve '{MicrosoftGraphAuthProvider.Name}' photo", ex);
         return(null);
     }
 }
Esempio n. 2
0
 public async Task<string> CreateMicrosoftPhotoUrlAsync(string accessToken, string savePhotoSize=null, CancellationToken token=default)
 {
     try
     {
         using var imageStream = await MicrosoftGraphAuthProvider.PhotoUrl(savePhotoSize)
             .GetStreamFromUrlAsync(requestFilter:req => req.AddBearerToken(accessToken), token: token);
         var base64 = Convert.ToBase64String(await imageStream.ReadFullyAsync(token));
         return "data:image/jpg;base64," + base64;
     }
     catch (Exception ex)
     {
         Log.Warn($"Could not retrieve '{MicrosoftGraphAuthProvider.Name}' photo", ex);
         return null;
     }
 }