|
23 | 23 | import org.pyload.android.client.module.TaskQueue; |
24 | 24 | import org.pyload.android.openapi.ApiClient; |
25 | 25 | import org.pyload.android.openapi.api.PyLoadRestApi; |
| 26 | +import org.pyload.android.openapi.auth.ApiKeyAuth; |
26 | 27 | import org.pyload.android.openapi.auth.HttpBasicAuth; |
| 28 | +import org.pyload.android.openapi.models.ServerStatus; |
27 | 29 |
|
28 | 30 | import javax.net.ssl.*; |
29 | 31 |
|
@@ -73,8 +75,7 @@ private boolean checkAuth() { |
73 | 75 | // replace protocol, some user also enter it |
74 | 76 | String host = prefs.getString("host", "10.0.2.2").replaceFirst("^[a-zA-z]+://", ""); |
75 | 77 | int port = Integer.parseInt(prefs.getString("port", "8000")); |
76 | | - String username = prefs.getString("username", "User"); |
77 | | - String password = prefs.getString("password", "pwhere"); |
| 78 | + String apiKey = prefs.getString("api_key", ""); |
78 | 79 |
|
79 | 80 | ApiClient apiClient = new ApiClient(); |
80 | 81 | apiClient.getOkBuilder() |
@@ -120,14 +121,14 @@ private boolean checkAuth() { |
120 | 121 |
|
121 | 122 | boolean authSuccessful; |
122 | 123 | try { |
123 | | - HttpBasicAuth basic_auth = new HttpBasicAuth(); |
124 | | - basic_auth.setCredentials(username, password); |
125 | | - apiClient.addAuthorization("basicAuth", basic_auth); |
| 124 | + ApiKeyAuth apiKeyAuth = new ApiKeyAuth("header", "X-API-Key"); |
| 125 | + apiKeyAuth.setApiKey(apiKey); |
| 126 | + apiClient.addAuthorization("ApiKeyAuth", apiKeyAuth); |
126 | 127 |
|
127 | 128 | PyLoadRestApi pyLoadRestApi = apiClient.createService(PyLoadRestApi.class); |
128 | 129 |
|
129 | | - Response<Map<String, Object>> checkAuth = pyLoadRestApi.apiCheckAuthGet(username, password).execute(); |
130 | | - authSuccessful = checkAuth.isSuccessful(); |
| 130 | + Response<ServerStatus> serverStatus = pyLoadRestApi.apiStatusServerGet().execute(); |
| 131 | + authSuccessful = serverStatus.isSuccessful(); |
131 | 132 | if (authSuccessful) { |
132 | 133 | client = pyLoadRestApi; |
133 | 134 | } |
|
0 commit comments