-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
41 deletions.
There are no files selected for viewing
22 changes: 20 additions & 2 deletions
22
...openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/fetch/Fetch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.