Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 1afa124

Browse files
committed
Add webfinger service and update the remote operation
1 parent f19b235 commit 1afa124

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/webfinger/GetOCInstanceViaWebfingerOperation.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,20 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
3131
import com.owncloud.android.lib.common.http.methods.nonwebdav.HttpMethod
3232
import com.owncloud.android.lib.common.operations.RemoteOperation
3333
import com.owncloud.android.lib.common.operations.RemoteOperationResult
34-
import com.owncloud.android.lib.resources.status.HttpScheme
3534
import com.owncloud.android.lib.resources.webfinger.responses.WebfingerJrdResponse
3635
import com.squareup.moshi.Moshi
3736
import timber.log.Timber
3837
import java.net.URL
3938

4039
class GetOCInstanceViaWebfingerOperation(
41-
private val lockupServerDomain:String,
42-
private val rel:String,
43-
private val resource:String
40+
private val lockupServerDomain: String,
41+
private val rel: String,
42+
private val resource: String,
4443
) : RemoteOperation<String>() {
4544

4645
private fun buildRequestUri() =
4746
Uri.parse(lockupServerDomain).buildUpon()
48-
.scheme(HttpScheme.HTTPS_SCHEME)
49-
.path(WEBFINGER_PATH)
47+
.path(ENDPOINT_WEBFINGER_PATH)
5048
.appendQueryParameter("rel", rel)
5149
.appendQueryParameter("resource", resource)
5250
.build()
@@ -73,9 +71,9 @@ class GetOCInstanceViaWebfingerOperation(
7371
return RemoteOperationResult<String>(method)
7472
}
7573

76-
private fun onRequestSuccessful(rawResponse:String): RemoteOperationResult<String> {
74+
private fun onRequestSuccessful(rawResponse: String): RemoteOperationResult<String> {
7775
val response = parseResponse(rawResponse)
78-
for(i in response.links) {
76+
for (i in response.links) {
7977
if (i.rel == rel) {
8078
val operationResult = RemoteOperationResult<String>(RemoteOperationResult.ResultCode.OK)
8179
operationResult.data = i.href
@@ -98,13 +96,13 @@ class GetOCInstanceViaWebfingerOperation(
9896
} else {
9997
onResultUnsuccessful(getMethod, response, status)
10098
}
101-
} catch(e: Exception) {
99+
} catch (e: Exception) {
102100
Timber.e(e, "Requesting webfinger info failed")
103101
RemoteOperationResult<String>(e)
104102
}
105103
}
106104

107105
companion object {
108-
val WEBFINGER_PATH = "/.well-known/webfinger"
106+
private const val ENDPOINT_WEBFINGER_PATH = "/.well-known/webfinger"
109107
}
110-
}
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* Copyright (C) 2022 ownCloud GmbH.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2,
8+
* as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.owncloud.android.lib.resources.webfinger.services
19+
20+
import com.owncloud.android.lib.common.OwnCloudClient
21+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
22+
23+
interface WebfingerService {
24+
fun getInstanceFromWebfinger(
25+
lookupServer: String,
26+
username: String,
27+
client: OwnCloudClient,
28+
): RemoteOperationResult<String>
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* ownCloud Android client application
3+
*
4+
* Copyright (C) 2022 ownCloud GmbH.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2,
8+
* as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.owncloud.android.lib.resources.webfinger.services.implementation
19+
20+
import com.owncloud.android.lib.common.OwnCloudClient
21+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
22+
import com.owncloud.android.lib.resources.webfinger.GetOCInstanceViaWebfingerOperation
23+
import com.owncloud.android.lib.resources.webfinger.services.WebfingerService
24+
25+
class OCWebfingerService : WebfingerService {
26+
27+
override fun getInstanceFromWebfinger(
28+
lookupServer: String,
29+
username: String,
30+
client: OwnCloudClient,
31+
): RemoteOperationResult<String> =
32+
GetOCInstanceViaWebfingerOperation(lookupServer, OWNCLOUD_REL, username).execute(client)
33+
34+
companion object {
35+
private const val OWNCLOUD_REL = "http://webfinger.owncloud/rel/server-instance"
36+
}
37+
38+
}

0 commit comments

Comments
 (0)