Skip to content

Commit

Permalink
fix: fetch initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmelati committed Oct 11, 2024
1 parent 3f39adf commit dccc21e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
package com.sphereon.oid.fed.client.fetch

import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import kotlin.jvm.JvmStatic

interface ICallbackService<PlatformCallbackType> {
fun register(platformCallback: PlatformCallbackType): ICallbackService<PlatformCallbackType>
}

interface IFetchService {
fun getHttpClient(): HttpClient
}

interface IFetchServiceInternal {
suspend fun fetchStatement(
endpoint: String
): String
}

interface IFetchCallbackService : ICallbackService<IFetchService>, IFetchService
interface IFetchCallbackService : ICallbackService<IFetchService>, IFetchService, IFetchServiceInternal

expect fun fetchService(): IFetchCallbackService

object FetchServiceObject : IFetchCallbackService {
@JvmStatic
private lateinit var platformCallback: IFetchService
private lateinit var httpClient: HttpClient

override suspend fun fetchStatement(endpoint: String): String {
return platformCallback.fetchStatement(endpoint)
return this.httpClient.get(endpoint) {
headers {
append(HttpHeaders.Accept, "application/entity-statement+jwt")
}
}.body()
}

override fun getHttpClient(): HttpClient {
return this.platformCallback.getHttpClient()
}

override fun register(platformCallback: IFetchService): IFetchCallbackService {
this.platformCallback = platformCallback
this.httpClient = this.platformCallback.getHttpClient()
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TrustChain(private val fetchService: IFetchCallbackService) {

val decodedEntityConfiguration = mapper.decodeJWTComponents(entityConfigurationJwt)


// need to verify JWT

val entityStatement: EntityConfigurationStatement =
Expand All @@ -59,7 +60,7 @@ class TrustChain(private val fetchService: IFetchCallbackService) {
entityIdentifier,
trustAnchors,
chain,
decodedEntityConfiguration.header.kid,
decodedEntityConfiguration.header.kid!!,
cache
)
if (result != null) {
Expand Down
Loading

0 comments on commit dccc21e

Please sign in to comment.