1
votes

I currently have a very simple rest api, wich allows user authentication through basic security. My angular client receives email and password from a login input, and gets the user from the server. email and password are sent in the http headers. The problem is, when my securityfilter (JAX-rs java, jersey backend impl) i get that my auth headers are empty.

Am i sending them empty from angular??

  getSecuredUser(email: string, password: string){
    let headers: Headers = new Headers();
    headers.append("Authorization", "Basic " + email + ":" + password);
    headers.append("'Access-Control-Allow-Origin': '*' ", "application/x-www-form-urlencoded");
    return this.http.get(DEFAULT_PATH + 'users/' + email, headers).subscribe(
      (data: Response) => {
        var result = data.json();
        return result;
      }
    );
  }
1
would you please check network debug console in your browser to check if it is containing AUTH headers or not? your code is looking fine - Mahmood Sajjadi

1 Answers

0
votes

your problem is the headers for the basic auth.

getSecuredUser(email: string, password: string){
    let headers: Headers = new Headers();
    headers.append("Authorization", "Basic " + btoa(`${email}:${password}`);
    headers.append("'Access-Control-Allow-Origin': '*' ", "application/x-www-form-urlencoded");
    return this.http.get(DEFAULT_PATH + 'users/' + email, {headers: headers}).subscribe(
      (data: Response) => {
        var result = data.json();
        return result;
      }
    );
  }