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.bmwconnecteddrive.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bmwconnecteddrive.internal.utils.Constants;
19 * The {@link Token} BMW ConnectedDrive 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;
28 private boolean myBmwApiUsage = false;
30 public boolean isMyBmwApiUsage() {
34 public void setMyBmwApiUsage(boolean myBmwAppUsage) {
35 this.myBmwApiUsage = myBmwAppUsage;
38 public String getBearerToken() {
39 return new StringBuilder(tokenType).append(Constants.SPACE).append(token).toString();
42 public void setToken(String token) {
46 public void setExpiration(int expiration) {
47 this.expiration = System.currentTimeMillis() / 1000 + expiration;
50 public void setType(String type) {
54 public boolean isValid() {
55 return (!token.equals(Constants.EMPTY) && !tokenType.equals(Constants.EMPTY)
56 && (this.expiration - System.currentTimeMillis() / 1000) > 1);
60 public String toString() {
61 return tokenType + token;