A function is currently operational, functioning by setting a value in the component when called (user.userImage).
getLoggedInUserPhoto() {
this.adalService.acquireToken('https://graph.microsoft.com')
.subscribe(token => {
let header = new HttpHeaders().set('Authorization', 'Bearer ' + token).set('Content-Type', 'image/jpeg');
this.imageService.getImage('https://graph.microsoft.com/v1.0/me/photo/$value', header)
.subscribe(blob => {
this.imageService.getImageUrlFromBlob(blob)
.then(res => {
this.user.userImage = res;
})
})
});
}
In attempting to replicate this functionality with a new function, I aim to have the function return a value rather than directly set it in the component. Despite searching extensively, I may be using incorrect search terms. Nevertheless, here is an attempt at achieving my desired outcome:
getPhoto(email: string): string {
return this.adalService.acquireToken('https://graph.microsoft.com')
.subscribe(token => {
let header = new HttpHeaders().set('Authorization', 'Bearer ' + token).set('Content-Type', 'image/jpeg');
this.imageService.getImage('https://graph.microsoft.com/v1.0/users/'+email+'/photo/$value', header)
.subscribe(blob => {
this.imageService.getImageUrlFromBlob(blob)
.then(res => {
return res;
})
})
});
}