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