我在理解我应该存储令牌(客户端)的位置时遇到了一些问题。所以每次我在服务器上更改页面时都会发送它。
@Override
public User getValue(HttpContext c) {
// This is where the credentials are extracted from the request
final String header = c.getRequest().getHeaderValue(CUSTOM_HEADER);
try {
if (header != null) {
final Optional<User> result = authenticator.authenticate(new Credentials(header,"",""));
if (result.isPresent()) {
return result.get();
}
}
} catch (AuthenticationException e) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
if (required) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
System.out.println("NO TOKEN RETURNING NULL");
return null;
}
}
这是我的身份验证在dropwizard中的样子。我需要使用HttpContext
发送令牌。
所以,如果我尝试进入adress/securedpage
。然后HttpContext
应该有此令牌。因此服务器知道用户是否有权访问
所以从客户端成功登录后。我应该在哪里放置从服务器收到的令牌?
答案 0 :(得分:1)
你有很多选择。这是理解利弊的良好环节 https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage/
silent_renew:true
进行配置,以便它在使用iframe(无需显式浏览器重定向)到期之前自动刷新令牌。