You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When querying facts on an authorizer, the returned types are com.clevercloud.biscuit.token.builder.Term - this class hierarchy does not have public accessors, so it is difficult to get the data out. (Except for Term.Str, which does have a getValue() )
minor: The toStrings look a little bit odd too, e.g. ""+value rather than String.valueOf(x)
sorry my test case is kotlin.
importcom.clevercloud.biscuit.crypto.KeyPairimportcom.clevercloud.biscuit.token.Biscuitimportcom.clevercloud.biscuit.token.builder.Termimportorg.junit.jupiter.api.Testimportstrikt.api.expectThatimportstrikt.assertions.isEqualToclassBiscuitTest {
val keypair =KeyPair()
@Test
fun`can put a fact in a biscuit and get it back out again`() {
val token =Biscuit.builder(keypair)
.add_authority_fact("""email("[email protected]")""")
.add_authority_fact("""id(123)""")
.build()
val tokenString = token.serialize_b64url().replace("=", "")
val authorizer =Biscuit.from_b64url(tokenString, keypair.public_key())
.verify(keypair.public_key())
.authorizer()
val email = authorizer.query("emailfact(\$name) <- email(\$name)")
.first { it.name() =="emailfact" }
.terms()
.first()
.stringValue()
expectThat(email).isEqualTo("[email protected]")
val id = authorizer.query("idfact(\$name) <- id(\$name)")
.first { it.name() =="idfact" }
.terms()
.first()
.intValue()
expectThat(id).isEqualTo(123) // might not work is a Term.Integer an int or a long?
}
}
fun Term.stringValue(): String {
returnwhen (this) {
isTerm.Str->this.value
else->throwIllegalArgumentException("Can only call on Term.Str")
}
}
fun Term.intValue(): Int {
returnwhen (this) {
isTerm.Integer->this.value // does not compile:- package-private, also, is a long?else->throwIllegalArgumentException("Can only call on Term.Integer")
}
}
The text was updated successfully, but these errors were encountered:
Thanks for a nice library.
When querying facts on an authorizer, the returned types are com.clevercloud.biscuit.token.builder.Term - this class hierarchy does not have public accessors, so it is difficult to get the data out. (Except for Term.Str, which does have a getValue() )
e.g. https://github.com/biscuit-auth/biscuit-java/blame/master/src/main/java/com/clevercloud/biscuit/token/builder/Term.java#L84
minor: The toStrings look a little bit odd too, e.g. ""+value rather than String.valueOf(x)
sorry my test case is kotlin.
The text was updated successfully, but these errors were encountered: