2017-09-11 2 views
0

내가 방법에 따라, JWT-인증을 사용하여 사용자 세부 사항을 가져 오기 위해 노력하고 API를

를 가져 오는 기본 JWT-인증 오류 반응 API를 가져 오는 기본 JWT-인증 오류 반응한다.

login() { 
    alert(this.state.UserName); 
    fetch (Api+''+'/wp-json/jwt-auth/v1/token',{ 
     method: "POST", 
     username: this.state.UserName, 
     password: this.state.Password 
    }).then((response) => response.json()) 
     .then((responseData) =>{ 
      console.log("LoginData:-" + JSON.stringify(responseData)); 
     }).done(); 
    } 
} 

과 점점 오류 : -

{ 
    "code":"[jwt_auth] empty_username", 
    "message":"<strong>ERROR</strong>: The username field is empty.", 
    "data":{"status":403} 
} 

사람이 도와주세요 알고있는 경우.

답변

0

당신의 API를 사용하면 인증 헤더

const base64 = require('base-64'); 
login() { 
    alert(this.state.UserName); 
    fetch (Api+''+'/wp-json/jwt-auth/v1/token',{ 
     method: "POST", 
     headers: { 
      'Authorization', 'Basic ' + base64.encode(this.state.UserName+ ":" + this.state.Password) 
     } 
    }).then((response) => response.json()) 
     .then((responseData) =>{ 
      console.log("LoginData:-" + JSON.stringify(responseData)); 
     }).done(); 
    } 
} 
으로 사용자 이름과 암호를 추가 할 필요가 기본 인증을 사용하는 경우