]> git.basschouten.com Git - openhab-addons.git/blob
504656f2042c94082c1e94a4bd40e3e0d0246e20
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mielecloud.internal.config;
14
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;
19
20 /**
21  * Handles OAuth 2 authorization processes.
22  *
23  * @author Björn Lange - Initial Contribution
24  */
25 @NonNullByDefault
26 public interface OAuthAuthorizationHandler {
27     /**
28      * Begins the authorization process after the user provided client ID, client secret and a bridge ID.
29      *
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.
35      */
36     void beginAuthorization(String clientId, String clientSecret, ThingUID bridgeUid, String email);
37
38     /**
39      * Creates the authorization URL for the ongoing authorization.
40      *
41      * @param redirectUri The URI to which the user is redirected after a successful login. This should point to our own
42      *            service.
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
46      *             cancelled.
47      */
48     String getAuthorizationUrl(String redirectUri);
49
50     /**
51      * Gets the UID of the bridge that is currently being authorized.
52      */
53     ThingUID getBridgeUid();
54
55     /**
56      * Gets the e-mail address associated with the account that is currently being authorized.
57      */
58     String getEmail();
59
60     /**
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
63      * persistent storage.
64      *
65      * @param redirectUrlWithParameters The URL the remote service redirected the user to. This is the URL our servlet
66      *            was called with.
67      * @throws NoOngoingAuthorizationException if there is no ongoing authorization.
68      * @throws OAuthException if the authorization failed. In this case the ongoing authorization is cancelled.
69      */
70     void completeAuthorization(String redirectUrlWithParameters);
71
72     /**
73      * Gets the access token from persistent storage.
74      *
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.
78      */
79     String getAccessToken(String email);
80 }