mirror of https://github.com/usbharu/Hideout.git
feat: Getリクエストも署名できるように
This commit is contained in:
parent
68d438bdb4
commit
54145dbde1
|
@ -44,6 +44,13 @@ suspend fun HttpClient.postAp(urlString: String, username: String, jsonLd: JsonL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun HttpClient.getAp(urlString: String,username: String):HttpResponse {
|
||||||
|
return this.get(urlString){
|
||||||
|
header("Accept",ContentType.Application.Activity)
|
||||||
|
header("Signature","keyId=\"$username\",algorithm=\"#rsa-sha\",headers=\"(request-target) digest date\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class HttpSignaturePluginConfig {
|
class HttpSignaturePluginConfig {
|
||||||
lateinit var keyMap: KeyMap
|
lateinit var keyMap: KeyMap
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ class ActivityPubFollowServiceImpl(
|
||||||
|
|
||||||
override suspend fun receiveFollowJob(props: JobProps<ReceiveFollowJob>) {
|
override suspend fun receiveFollowJob(props: JobProps<ReceiveFollowJob>) {
|
||||||
val actor = props[ReceiveFollowJob.actor]
|
val actor = props[ReceiveFollowJob.actor]
|
||||||
val person = activityPubUserService.fetchPerson(actor)
|
|
||||||
val follow = Config.configData.objectMapper.readValue<Follow>(props[ReceiveFollowJob.follow])
|
|
||||||
val targetActor = props[ReceiveFollowJob.targetActor]
|
val targetActor = props[ReceiveFollowJob.targetActor]
|
||||||
|
val person = activityPubUserService.fetchPerson(actor,targetActor)
|
||||||
|
val follow = Config.configData.objectMapper.readValue<Follow>(props[ReceiveFollowJob.follow])
|
||||||
httpClient.postAp(
|
httpClient.postAp(
|
||||||
urlString = person.inbox ?: throw IllegalArgumentException("inbox is not found"),
|
urlString = person.inbox ?: throw IllegalArgumentException("inbox is not found"),
|
||||||
username = "$targetActor#pubkey",
|
username = "$targetActor#pubkey",
|
||||||
|
|
|
@ -5,5 +5,5 @@ import dev.usbharu.hideout.domain.model.ap.Person
|
||||||
interface ActivityPubUserService {
|
interface ActivityPubUserService {
|
||||||
suspend fun getPersonByName(name:String): Person
|
suspend fun getPersonByName(name:String): Person
|
||||||
|
|
||||||
suspend fun fetchPerson(url:String): Person
|
suspend fun fetchPerson(url: String, targetActor: String? = null): Person
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import dev.usbharu.hideout.domain.model.ap.Person
|
||||||
import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto
|
import dev.usbharu.hideout.domain.model.hideout.dto.RemoteUserCreateDto
|
||||||
import dev.usbharu.hideout.exception.UserNotFoundException
|
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||||
import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException
|
import dev.usbharu.hideout.exception.ap.IllegalActivityPubObjectException
|
||||||
|
import dev.usbharu.hideout.plugins.getAp
|
||||||
import dev.usbharu.hideout.service.impl.IUserService
|
import dev.usbharu.hideout.service.impl.IUserService
|
||||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
|
@ -52,7 +53,7 @@ class ActivityPubUserServiceImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun fetchPerson(url: String): Person {
|
override suspend fun fetchPerson(url: String, targetActor: String?): Person {
|
||||||
return try {
|
return try {
|
||||||
val userEntity = userService.findByUrl(url)
|
val userEntity = userService.findByUrl(url)
|
||||||
return Person(
|
return Person(
|
||||||
|
@ -80,9 +81,13 @@ class ActivityPubUserServiceImpl(
|
||||||
)
|
)
|
||||||
|
|
||||||
} catch (e: UserNotFoundException) {
|
} catch (e: UserNotFoundException) {
|
||||||
val httpResponse = httpClient.get(url) {
|
val httpResponse = if (targetActor != null) {
|
||||||
|
httpClient.getAp(url,"$targetActor#pubkey")
|
||||||
|
}else {
|
||||||
|
httpClient.get(url) {
|
||||||
accept(ContentType.Application.Activity)
|
accept(ContentType.Application.Activity)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
val person = Config.configData.objectMapper.readValue<Person>(httpResponse.bodyAsText())
|
val person = Config.configData.objectMapper.readValue<Person>(httpResponse.bodyAsText())
|
||||||
|
|
||||||
userService.createRemoteUser(
|
userService.createRemoteUser(
|
||||||
|
|
|
@ -85,7 +85,7 @@ class ActivityPubFollowServiceImplTest {
|
||||||
|
|
||||||
)
|
)
|
||||||
val activityPubUserService = mock<ActivityPubUserService> {
|
val activityPubUserService = mock<ActivityPubUserService> {
|
||||||
onBlocking { fetchPerson(anyString()) } doReturn person
|
onBlocking { fetchPerson(anyString(), any()) } doReturn person
|
||||||
}
|
}
|
||||||
val userService = mock<IUserService> {
|
val userService = mock<IUserService> {
|
||||||
onBlocking { findByUrls(any()) } doReturn listOf(
|
onBlocking { findByUrls(any()) } doReturn listOf(
|
||||||
|
|
Loading…
Reference in New Issue