]> git.basschouten.com Git - openhab-addons.git/blob
61f97289f0bfcc6a42d951f9b3e0785225b21d4f
[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 org.openhab.core.auth.client.oauth2.OAuthException if the authorization URL cannot be determined. In this
46      *             case the ongoing authorization is
47      *             cancelled.
48      */
49     String getAuthorizationUrl(String redirectUri);
50
51     /**
52      * Gets the UID of the bridge that is currently being authorized.
53      */
54     ThingUID getBridgeUid();
55
56     /**
57      * Gets the e-mail address associated with the account that is currently being authorized.
58      */
59     String getEmail();
60
61     /**
62      * Completes the authorization by extracting the authorization code from the given redirection URL, fetching the
63      * access token response and persisting it. After this method succeeded the access token can be read from the
64      * persistent storage.
65      *
66      * @param redirectUrlWithParameters The URL the remote service redirected the user to. This is the URL our servlet
67      *            was called with.
68      * @throws NoOngoingAuthorizationException if there is no ongoing authorization.
69      * @throws org.openhab.core.auth.client.oauth2.OAuthException if the authorization failed. In this case the ongoing
70      *             authorization is cancelled.
71      */
72     void completeAuthorization(String redirectUrlWithParameters);
73
74     /**
75      * Gets the access token from persistent storage.
76      *
77      * @param email E-mail address for which the access token is requested.
78      * @return The access token.
79      * @throws org.openhab.core.auth.client.oauth2.OAuthException if the access token cannot be obtained.
80      */
81     String getAccessToken(String email);
82 }