[wip] minor additions
This commit is contained in:
parent
b950c9ebdb
commit
ca0bd8d67a
3 changed files with 208 additions and 0 deletions
59
src/de/pzzz/vertx/oauth/OAuthToken.java
Executable file
59
src/de/pzzz/vertx/oauth/OAuthToken.java
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
package de.pzzz.vertx.oauth;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Represents an OAuth2 Token as received from IAM via client credentials flow.
|
||||
*/
|
||||
public class OAuthToken implements Serializable {
|
||||
private static final long serialVersionUID = -1712414758315937247L;
|
||||
|
||||
private static final Integer EXPIRATION_OFFSET = 30;
|
||||
|
||||
@JsonProperty("access_token")
|
||||
private String token;
|
||||
@JsonProperty("token_type")
|
||||
private String type;
|
||||
@JsonProperty("expires_in")
|
||||
private Integer expiresIn;
|
||||
|
||||
@JsonIgnore
|
||||
private final Date issued;
|
||||
|
||||
public OAuthToken() {
|
||||
issued = new Date();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
int diffSeconds = (int) Math.ceil((new Date().getTime() - issued.getTime())/1000f);
|
||||
return diffSeconds < (expiresIn - EXPIRATION_OFFSET);
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(final String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(final Integer expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue