mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Add webfinger service and update the remote operation
This commit is contained in:
parent
f19b2355b4
commit
1afa124b7d
@ -31,22 +31,20 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
|
||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.HttpMethod
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.resources.status.HttpScheme
|
||||
import com.owncloud.android.lib.resources.webfinger.responses.WebfingerJrdResponse
|
||||
import com.squareup.moshi.Moshi
|
||||
import timber.log.Timber
|
||||
import java.net.URL
|
||||
|
||||
class GetOCInstanceViaWebfingerOperation(
|
||||
private val lockupServerDomain:String,
|
||||
private val rel:String,
|
||||
private val resource:String
|
||||
private val lockupServerDomain: String,
|
||||
private val rel: String,
|
||||
private val resource: String,
|
||||
) : RemoteOperation<String>() {
|
||||
|
||||
private fun buildRequestUri() =
|
||||
Uri.parse(lockupServerDomain).buildUpon()
|
||||
.scheme(HttpScheme.HTTPS_SCHEME)
|
||||
.path(WEBFINGER_PATH)
|
||||
.path(ENDPOINT_WEBFINGER_PATH)
|
||||
.appendQueryParameter("rel", rel)
|
||||
.appendQueryParameter("resource", resource)
|
||||
.build()
|
||||
@ -73,9 +71,9 @@ class GetOCInstanceViaWebfingerOperation(
|
||||
return RemoteOperationResult<String>(method)
|
||||
}
|
||||
|
||||
private fun onRequestSuccessful(rawResponse:String): RemoteOperationResult<String> {
|
||||
private fun onRequestSuccessful(rawResponse: String): RemoteOperationResult<String> {
|
||||
val response = parseResponse(rawResponse)
|
||||
for(i in response.links) {
|
||||
for (i in response.links) {
|
||||
if (i.rel == rel) {
|
||||
val operationResult = RemoteOperationResult<String>(RemoteOperationResult.ResultCode.OK)
|
||||
operationResult.data = i.href
|
||||
@ -98,13 +96,13 @@ class GetOCInstanceViaWebfingerOperation(
|
||||
} else {
|
||||
onResultUnsuccessful(getMethod, response, status)
|
||||
}
|
||||
} catch(e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Requesting webfinger info failed")
|
||||
RemoteOperationResult<String>(e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val WEBFINGER_PATH = "/.well-known/webfinger"
|
||||
private const val ENDPOINT_WEBFINGER_PATH = "/.well-known/webfinger"
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* Copyright (C) 2022 ownCloud GmbH.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.webfinger.services
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
|
||||
interface WebfingerService {
|
||||
fun getInstanceFromWebfinger(
|
||||
lookupServer: String,
|
||||
username: String,
|
||||
client: OwnCloudClient,
|
||||
): RemoteOperationResult<String>
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* Copyright (C) 2022 ownCloud GmbH.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.webfinger.services.implementation
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.resources.webfinger.GetOCInstanceViaWebfingerOperation
|
||||
import com.owncloud.android.lib.resources.webfinger.services.WebfingerService
|
||||
|
||||
class OCWebfingerService : WebfingerService {
|
||||
|
||||
override fun getInstanceFromWebfinger(
|
||||
lookupServer: String,
|
||||
username: String,
|
||||
client: OwnCloudClient,
|
||||
): RemoteOperationResult<String> =
|
||||
GetOCInstanceViaWebfingerOperation(lookupServer, OWNCLOUD_REL, username).execute(client)
|
||||
|
||||
companion object {
|
||||
private const val OWNCLOUD_REL = "http://webfinger.owncloud/rel/server-instance"
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user