default HttpResponse<RAuth> auth(String username, String password)
throws UnirestException, KevoreeRegistryException {
HttpResponse<RAuth> res = Unirest.post(this.baseUrl() + "/oauth/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.field("grant_type", "password")
.field("username", username)
.field("password", password)
.field("scope", "read write")
.field("client_id", config().getString("registry.oauth.client_id"))
.field("client_secret", config().getString("registry.oauth.client_secret"))
.asObject(RAuth.class);
RAuth auth = res.getBody();
auth.setExpiresAt((System.currentTimeMillis() / 1000L) + auth.getExpiresIn());
if (res.getStatus() == 200) {
try {
config().save();
} catch (IOException e) {
throw new KevoreeRegistryException("Unable to update config file", e);
}
}
return res;
}