2 * Copyright (c) 2010-2023 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.mielecloud.internal.auth;
15 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * An {@link OAuthTokenRefresher} offers convenient access to OAuth 2 authentication related functionality,
21 * especially refreshing the access token.
23 * @author Roland Edelhoff - Initial contribution
24 * @author Björn Lange - Allow removing tokens from the storage
27 public interface OAuthTokenRefresher {
29 * Sets the listener that is called when the access token was refreshed.
31 * @param listener The listener to register.
32 * @param serviceHandle The service handle identifying the internal OAuth configuration.
33 * @throws OAuthException if the listener needs to be registered at an underlying service which is not available
34 * because the account has not yet been authorized
36 public void setRefreshListener(OAuthTokenRefreshListener listener, String serviceHandle);
41 * @param serviceHandle The service handle identifying the internal OAuth configuration.
43 public void unsetRefreshListener(String serviceHandle);
46 * Refreshes the access and refresh tokens for the given service handle. If an {@link OAuthTokenRefreshListener} is
47 * registered for the service handle then it is notified after the refresh has completed.
49 * This call will succeed if the access token is still valid or a valid refresh token exists, which can be used to
50 * refresh the expired access token. If refreshing fails, an {@link OAuthException} is thrown.
52 * @param serviceHandle The service handle identifying the internal OAuth configuration.
53 * @throws OAuthException if the token cannot be obtained or refreshed
55 public void refreshToken(String serviceHandle);
58 * Gets the currently stored access token from persistent storage.
60 * @param serviceHandle The service handle identifying the internal OAuth configuration.
61 * @return The currently stored access token or an empty {@link Optional} if there is no stored token.
63 public Optional<String> getAccessTokenFromStorage(String serviceHandle);
66 * Removes the tokens from persistent storage.
68 * Note: Calling this method will force the user to run through the pairing process again in order to obtain a
71 * @param serviceHandle The service handle identifying the internal OAuth configuration.
73 public void removeTokensFromStorage(String serviceHandle);