-1
I am having problems doing the authentication in an api with JWT standard, the token it comes in header and using the retrofit I am not getting it. The consumption of the api in Postman usually occurs the login resource, in the body a json with the e-mail credentials and password, the request returns an empty body, already observing the header we located the information of the token. When implementing the login on android always fall on onFailure ie I’m not sure how to get/read the information that is in the header.
I’m putting my code down first on the interface
@Headers({"Content-Type: application/json", "Accept: application/json"})
@POST("login")
Call<Authorization> login(@Body Credenciais cred);
now where I am consuming, what strikes me is that I know the api it returns me an empty body and the information I want is in the header so when I have a Call to Authorization this in my view would not be correct because the retrofit it will want to parse the return to the object only that in the body comes back nothing and then.... could be that this is the cause of the problem
private void authenticate(String email, String password) {
Log.i(TAG, "authenticate()" );
Credenciais creds = new Credenciais(email, password);
ApiUtil.getServiceClass().login(creds)
.enqueue(new Callback<Authorization>() {
@Override
public void onResponse(Call<Authorization> call, Response<Authorization> response) {
if (response.isSuccessful()) {
Log.i(TAG, "Token: " + response.headers().get("Authorization"));
} else {
Log.i(TAG, "onResponse() - Não foi um sucesso");
}
}
@Override
public void onFailure(Call<Authorization> call, Throwable t) {
Log.i(TAG, "onFailure() - Opá ocorreu uma falha " + t.getMessage());
call.cancel();
}
});