All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sts.oda.client.model.AccessToken Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package sts.oda.client.model;

import com.google.gson.annotations.SerializedName;
import org.joda.time.LocalTime;
import sts.oda.client.utils.Clock;
import sts.oda.client.utils.Jwt;

import java.io.IOException;

public class AccessToken {
    @SerializedName("access_token")
    private String accessToken;

    @SerializedName("token_type")
    private String tokenType;

    @SerializedName("expires_in")
    private String expiresIn;

    @SerializedName("pay_load")
    private Jwt payload;

    @SerializedName("time_provider")
    private LocalTime timeProvider;

    public AccessToken accessToken(String accessToken) {
        this.accessToken = accessToken;
        return this;
    }

    public AccessToken payload(Jwt payload) {
        this.payload = payload;
        return this;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public boolean isExpired() {
        if(this.payload == null){
            try{
                Jwt temp = decodeJwt(accessToken);
                return temp.isExpired();
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        return this.payload.isExpired();
    }

    private Jwt decodeJwt(String jwt) throws Exception {
        String[] segments = jwt.split("\\.");

        Jwt payload = null;
        if (segments.length != 3) {
            throw new Exception("Invalid Token");
        }
        try {
            payload = new Jwt(jwt, new Clock());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return payload;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy