start second (or third?) reborn

This commit is contained in:
2024-02-16 13:40:47 +06:00
parent ff973e63fc
commit e98a484c4d
72 changed files with 173 additions and 200 deletions
build.gradle
client/src/androidMain
defaultAndroidSettings.gradleextensions.gradle
features
auth
client
common
server
src
jvmMain
kotlin
dev
inmo
postssystem
client
template
client
common
common
client
src
jsMain
kotlin
dev
inmo
postssystem
features
common
main
common
src
commonMain
kotlin
dev
inmo
postssystem
features
jvmMain
kotlin
dev
inmo
postssystem
features
linuxX64Main
kotlin
dev
inmo
postssystem
features
main
mingwX64Main
kotlin
dev
inmo
postssystem
features
content
binary
client
common
client
common
text
client
common
files
client
src
commonMain
kotlin
dev
inmo
postssystem
features
main
common
src
jvmMain
kotlin
dev
inmo
postssystem
features
main
posts
client
common
src
commonMain
kotlin
dev
inmo
postssystem
features
posts
common
main
server
src
jvmMain
kotlin
dev
inmo
postssystem
features
publication
client
common
roles
client
common
manager
client
common
status
client
src
commonMain
kotlin
dev
inmo
postssystem
features
main
common
template
client
common
users
client
common
build.gradle
src
commonMain
kotlin
dev
inmo
postssystem
features
users
common
jvmMain
kotlin
dev
inmo
postssystem
features
main
gradle
mppAndroidProject.gradlemppJavaProject.gradlemppJsProject.gradlemppProjectWithSerialization.gradle
publicators
simple
client
src
common
src
template
client
src
common
src
publish.gradle
services
posts
client
src
common
src
template
client
src
common
src
settings.gradle
targets/telegram
content
polls
client
src
common
src
loader
client
src
common
src
template
client
src
common
src

@ -1,7 +1,6 @@
package dev.inmo.postssystem.features.auth.client
import dev.inmo.micro_utils.common.Either
import dev.inmo.micro_utils.ktor.client.UnifiedRequester
import dev.inmo.postssystem.features.auth.common.AuthKey
import dev.inmo.postssystem.features.auth.common.AuthTokenInfo
import dev.inmo.postssystem.features.common.common.AdditionalModules
@ -27,7 +26,6 @@ fun createAuthorizedFeaturesDIModule(
installClientAuthenticator(serverUrl, get(), get(AuthorizedQualifiers.CredsQualifier), onAuthKeyUpdated, onUserRetrieved, onAuthKeyInvalidated)
}
}
single { UnifiedRequester(get(), get()) }
single { StatusFeatureClient(get(AuthorizedQualifiers.ServerUrlQualifier), get()) }
AdditionalModules.Authorized.modules.forEach {

@ -2,14 +2,14 @@ package dev.inmo.postssystem.features.auth.client
import dev.inmo.postssystem.features.auth.common.*
import dev.inmo.postssystem.features.users.common.User
import dev.inmo.micro_utils.ktor.client.UnifiedRequester
import dev.inmo.micro_utils.ktor.client.bodyOrNull
import dev.inmo.micro_utils.ktor.common.buildStandardUrl
import io.ktor.client.HttpClient
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.*
import kotlinx.serialization.builtins.nullable
class ClientAuthFeature(
private val requester: UnifiedRequester,
private val client: HttpClient,
baseUrl: String
) : AuthFeature {
private val rootUrl = buildStandardUrl(baseUrl.dropLastWhile { it == '/' }, authRootPathPart)
@ -26,28 +26,23 @@ class ClientAuthFeature(
authGetMePathPart
)
constructor(client: HttpClient, rootUrl: String): this(
UnifiedRequester(client),
rootUrl
)
override suspend fun auth(creds: AuthCreds): AuthTokenInfo? = client.post(
fullAuthPath
) {
setBody(creds)
}.bodyOrNull()
override suspend fun auth(creds: AuthCreds): AuthTokenInfo? = requester.unipost(
fullAuthPath,
AuthCreds.serializer() to creds,
AuthTokenInfo.serializer().nullable
)
override suspend fun refresh(refresh: RefreshToken): AuthTokenInfo? = client.post(
fullRefreshPath
) {
setBody(refresh)
}.bodyOrNull()
override suspend fun refresh(refresh: RefreshToken): AuthTokenInfo? = requester.unipost(
fullRefreshPath,
RefreshToken.serializer() to refresh,
AuthTokenInfo.serializer().nullable
)
override suspend fun getMe(authToken: AuthToken): User? = requester.unipost(
fullGetMePath,
AuthToken.serializer() to authToken,
User.serializer().nullable
)
override suspend fun getMe(authToken: AuthToken): User? = client.post(
fullGetMePath
) {
setBody(authToken)
}.bodyOrNull()
fun isAuthRequest(builder: HttpRequestBuilder): Boolean = builder.url.buildString().let {
it == fullAuthPath || it == fullRefreshPath

@ -37,7 +37,7 @@ fun HttpClientConfig<*>.installClientAuthenticator(
}.onSecond {
currentRefreshToken = it.refresh
}
val creds = initialAuthKey.t1 as? AuthCreds
val creds = initialAuthKey.t1OrNull as? AuthCreds
var userRefreshJob: Job? = null
install("Auth Token Refresher") {

@ -1 +0,0 @@
<manifest package="dev.inmo.postssystem.features.auth.client"/>

@ -1 +0,0 @@
<manifest package="dev.inmo.postssystem.features.auth.common"/>

@ -1,6 +1,6 @@
package dev.inmo.postssystem.features.auth.server.tokens
import com.soywiz.klock.DateTime
import korlibs.time.DateTime
import dev.inmo.postssystem.features.auth.common.AuthToken
import dev.inmo.postssystem.features.auth.common.RefreshToken
import dev.inmo.postssystem.features.users.common.UserId

@ -1,7 +1,7 @@
package dev.inmo.postssystem.features.auth.server.tokens
import com.soywiz.klock.DateTime
import com.soywiz.klock.milliseconds
import korlibs.time.DateTime
import korlibs.time.milliseconds
import dev.inmo.postssystem.features.auth.common.*
import dev.inmo.postssystem.features.common.common.Milliseconds
import dev.inmo.postssystem.features.users.common.*