0

I have an API, which I need to consume to create reports, However that API requires username and password to access it, by using curl command I can access the API

curl -X GET "https://SomeApiCall/api/v1/customers/" -H "accept:application/json; charset=UTF-8" -u "username:password"

but when I am trying to use same API using angular I am getting below error

key:"api.error.invalid_auth_schema"
message: "Invalid authentication scheme is used. Only Basic Authentication scheme is supported (login and password should be provided)"

Angular sample code:

 this.data = this.http.get("https://SomeApiCall/api/v1/customers/" , {
      headers: new HttpHeaders({
        'Authorization': 'Basic' + btoa('username:password'),
        'Content-Type':  'application/json'
      })
    });

Can someone explain, what mistake I am making ?

3
  • 1
    You're missing a space in the auth header. Commented Jan 25, 2021 at 8:26
  • 2
    'Authorization': 'Basic ' + btoa('username:password') Commented Jan 25, 2021 at 8:27
  • @jonrsharpe, Deipirscher : yeah you both are right, thanks alot :) Commented Jan 25, 2021 at 8:34

1 Answer 1

1

I think the problem is that you don't have a space after 'Basic'. Change to:

 this.data = this.http.get("https://SomeApiCall/api/v1/customers/" , {
  headers: new HttpHeaders({
    'Authorization': 'Basic ' + btoa('username:password'),
    'Content-Type':  'application/json'
  })
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.