Skip to content

Instantly share code, notes, and snippets.

@nelsondev19
Last active May 21, 2023 16:51
Show Gist options
  • Save nelsondev19/7e945be76502e1bd50e9af38418bf74f to your computer and use it in GitHub Desktop.
Save nelsondev19/7e945be76502e1bd50e9af38418bf74f to your computer and use it in GitHub Desktop.
Get profile image from Microsoft with TypeScript
export const getImageProfileMicrosoft = (accessToken: string) => {
const headers = new Headers();
headers.append("Authorization", `Bearer ${accessToken}`);
fetch("https://graph.microsoft.com/v1.0/me/photo/$value", {
method: "GET",
headers: headers,
})
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.blob();
})
.then((blob) => {
const url = URL.createObjectURL(blob);
const image = document.getElementById("profileImage");
image.src = url;
})
.catch((error) => console.error("There was a problem:", error));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment