2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mybmw.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.mybmw.internal.utils.Constants;
19 * The {@link Token} MyBMW Token storage
21 * @author Bernd Weymann - Initial contribution
25 private String token = Constants.EMPTY;
26 private String tokenType = Constants.EMPTY;
27 private long expiration = 0;
29 public String getBearerToken() {
30 return new StringBuilder(tokenType).append(Constants.SPACE).append(token).toString();
33 public void setToken(String token) {
37 public void setExpiration(int expiration) {
38 this.expiration = System.currentTimeMillis() / 1000 + expiration;
41 public void setExpirationTotal(long expiration) {
42 this.expiration = expiration;
45 public void setType(String type) {
49 public boolean isValid() {
50 return (!token.equals(Constants.EMPTY) && !tokenType.equals(Constants.EMPTY)
51 && (this.expiration - System.currentTimeMillis() / 1000) > 1);
55 public String toString() {
56 return tokenType + Constants.COLON + token + Constants.COLON + isValid();