Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Mar 22, 2024
1 parent f0a287c commit e2897be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ open class DefaultAuthHeaderSigner(val expiration: Duration = 15.minutes) : Auth
}

fun createBuilder(timeExp: Instant, claims: Map<String, String>): JwtBuilder {
return Jwts.builder()
.issuedAt(Date.from(Instant.now()))
.expiration(Date.from(timeExp))
.also { builder -> claims.forEach { builder.claim(it.key, it.value) } }
return Jwts.builder().issuedAt(Date.from(Instant.now())).expiration(Date.from(timeExp)).also {
builder ->
claims.forEach { builder.claim(it.key, it.value) }
}
}
}
12 changes: 7 additions & 5 deletions wallet-sdk/src/test/kotlin/org/stellar/walletsdk/AuthTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.ktor.http.*
import java.time.Instant
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.time.Duration.Companion.days
import kotlinx.coroutines.runBlocking
import kotlinx.datetime.Clock
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -82,11 +81,11 @@ internal class AuthTest : SuspendTest() {

@Test
fun `create token test custodial`() {
val signer = DefaultAuthHeaderSigner(100000.days)
val signer = DefaultAuthHeaderSigner()
val accountKp =
SigningKeyPair.fromSecret("SBPPLU2KO3PDBLSDFIWARQSW5SAOIHTJDUQIWN3BQS7KPNMVUDSU37QO")
val memo = "1234567"
val url = "https://auth.example.com/?account=${accountKp.address}&memo=$memo"
val url = "https://example.com/sep10/auth?account=${accountKp.address}&memo=$memo"
val builder = URLBuilder(url)
val params = mapOf("account" to accountKp.address, "memo" to memo)

Expand All @@ -107,6 +106,7 @@ internal class AuthTest : SuspendTest() {
assertEquals(accountKp.address, claims.payload["account"])
assertEquals(memo, claims.payload["memo"])

println(url)
println(token)
}

Expand All @@ -118,7 +118,7 @@ internal class AuthTest : SuspendTest() {
SigningKeyPair.fromSecret("SCYVDFYEHNDNTB2UER2FCYSZAYQFAAZ6BDYXL3BWRQWNL327GZUXY7D7")
// Signing with a domain signer
val signer =
object : DefaultAuthHeaderSigner(100000.days) {
object : DefaultAuthHeaderSigner() {
override fun createToken(
claims: Map<String, String>,
clientDomain: String?,
Expand All @@ -133,7 +133,8 @@ internal class AuthTest : SuspendTest() {
}
}
val clientDomain = "example-wallet.stellar.org"
val url = "https://auth.example.com/?account=${accountKp.address}&client_domain=${clientDomain}"
val url =
"https://example.com/sep10/auth?account=${accountKp.address}&client_domain=${clientDomain}"
val builder = URLBuilder(url)
val params = mapOf("account" to accountKp.address, "client_domain" to clientDomain)

Expand All @@ -152,6 +153,7 @@ internal class AuthTest : SuspendTest() {
assertEquals(accountKp.address, claims.payload["account"])
assertEquals(clientDomain, claims.payload["client_domain"])

println(url)
println(token)
}
}

0 comments on commit e2897be

Please sign in to comment.