Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

java - Checking if access token isnt expired

I have application which gives access token after authentication and I want to check if token is not expired

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String expires_in;

public boolean isNotExpired() {
        return ! Instant.now().isBefore(Instant.parse(expires_in));
    }

But after I run application I get errors:

JSON encoding error: Text '3600' could not be parsed at index 4; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Text '3600' could not be parsed at index 4 (through reference chain: com.Auth.AuthInfo["notExpired"])

How can I fix this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Why do you keep the value of 3600 there instead of the actual date-time of the expiration?

It will easily solve your problem. If you want to keep how long the token is valid you would also need the issue time of the token to check that the diff of current time - issue time is not greater than the value of a field like validFor.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...