]> git.basschouten.com Git - openhab-addons.git/blob
ac83306bed6a86aac73b12171de26618fa6d6f34
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.tado.internal.api;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.tado.internal.api.auth.Authorizer;
17 import org.openhab.binding.tado.internal.api.auth.OAuthAuthorizer;
18 import org.openhab.binding.tado.internal.api.client.HomeApi;
19
20 import com.google.gson.Gson;
21
22 /**
23  * Factory to create and configure {@link HomeApi} instances.
24  *
25  * @author Dennis Frommknecht - Initial contribution
26  */
27 @NonNullByDefault
28 public class HomeApiFactory {
29     private static final String OAUTH_SCOPE = "home.user";
30     private static final String OAUTH_CLIENT_ID = "public-api-preview";
31     private static final String OAUTH_CLIENT_SECRET = "4HJGRffVR8xb3XdEUQpjgZ1VplJi6Xgw";
32
33     public HomeApi create(String username, String password) {
34         Gson gson = GsonBuilderFactory.defaultGsonBuilder().create();
35         Authorizer authorizer = new OAuthAuthorizer().passwordFlow(username, password).clientId(OAUTH_CLIENT_ID)
36                 .clientSecret(OAUTH_CLIENT_SECRET).scopes(OAUTH_SCOPE);
37         return new HomeApi(gson, authorizer);
38     }
39 }