首页 > 解决方案 > AWT 令牌生成类似令牌

问题描述

为什么当我发出以每 10 毫秒生成一个新令牌时算法返回相同的令牌

// generate a token every 10ms        

@Scheduled(fixedRate=10)
public void work() {
    // get user information
    UserProfile newuser = new UserProfile("abc", "abc123");

    //generate the token 
    String jwt = tokenProvider.generateToken(newuser);

    // print the token                           
    System.out.println(jwt);
}

如果我在 1000 毫秒内发出新令牌,则返回相同的令牌

标签: javaspringspring-securityjwt

解决方案


Since you aren't changing anything else, the issued time probably isn't measured down below a second by default.

I would add a token uuid to each token to differentiate the generated token string.


推荐阅读