skip to Main Content

I am trying to retrieve an image from Azure blob, but I am getting a 403 response with the following message,

"403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature."

Following is the code I used to retrieve the image

public getBase64Image(): Observable<string>{
    return this.http.get(environment.receiptLogoUrl, { responseType: 'blob' })
      .pipe(
        switchMap((blob: Blob) => {
          return new Observable<string>((observer) => {
            const reader = new FileReader();
            reader.readAsBinaryString(blob);
            reader.onloadend = () => {
              const base64data = btoa(reader.result as string);
              observer.next(`data:image/png;base64,${base64data}`);
              observer.complete();
            };
          });
        })
      );
  }

How should this issue be fixed?

2

Answers


  1. Chosen as BEST ANSWER

  2. The error says the authentication is failing, so you need to authenticate the request. Here are the two main ways to provide authentication for Azure blobs:

    1. Use the account access key
    2. Use Active Directory (AD)

    First check the Azure portal to see which authentication method is currently set. Then follow the appropriate instructions on how to authenticate with that method. There are more details here:

    https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-data-operations-portal#navigate-to-blobs-in-the-azure-portal

    If you’re using AD, AAD, MSA, sign in with google/facebook/linkedin/MS, etc, there is an Angular library that can help with this:

    https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-authentication-sample-angular-spa-app

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search