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.config;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.mielecloud.internal.config.exception.NoOngoingAuthorizationException;
17 import org.openhab.binding.mielecloud.internal.config.exception.OngoingAuthorizationException;
18 import org.openhab.core.thing.ThingUID;
21 * Handles OAuth 2 authorization processes.
23 * @author Björn Lange - Initial Contribution
26 public interface OAuthAuthorizationHandler {
28 * Begins the authorization process after the user provided client ID, client secret and a bridge ID.
30 * @param clientId Client ID.
31 * @param clientSecret Client secret.
32 * @param bridgeUid The UID of the bridge to authorize.
33 * @param email E-mail address identifying the account to authorize.
34 * @throws OngoingAuthorizationException if there already is an ongoing authorization.
36 void beginAuthorization(String clientId, String clientSecret, ThingUID bridgeUid, String email);
39 * Creates the authorization URL for the ongoing authorization.
41 * @param redirectUri The URI to which the user is redirected after a successful login. This should point to our own
43 * @return The authorization URL to which the user is redirected for the log in.
44 * @throws NoOngoingAuthorizationException if there is no ongoing authorization.
45 * @throws OAuthException if the authorization URL cannot be determined. In this case the ongoing authorization is
48 String getAuthorizationUrl(String redirectUri);
51 * Gets the UID of the bridge that is currently being authorized.
53 ThingUID getBridgeUid();
56 * Gets the e-mail address associated with the account that is currently being authorized.
61 * Completes the authorization by extracting the authorization code from the given redirection URL, fetching the
62 * access token response and persisting it. After this method succeeded the access token can be read from the
65 * @param redirectUrlWithParameters The URL the remote service redirected the user to. This is the URL our servlet
67 * @throws NoOngoingAuthorizationException if there is no ongoing authorization.
68 * @throws OAuthException if the authorization failed. In this case the ongoing authorization is cancelled.
70 void completeAuthorization(String redirectUrlWithParameters);
73 * Gets the access token from persistent storage.
75 * @param email E-mail address for which the access token is requested.
76 * @return The access token.
77 * @throws OAuthException if the access token cannot be obtained.
79 String getAccessToken(String email);