Skip to content

Commit

Permalink
add claim names #17 and android level to readme #18 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
nefilim authored Jan 24, 2022
1 parent 55148f6 commit 50c671f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Please make sure you have [Arrow Core](https://arrow-kt.io/docs/core/#Gradle-kot

For examples see: [JWTSpec.kt](https://github.com/nefilim/kjwt/blob/main/core/src/test/kotlin/io/github/nefilim/kjwt/JWTSpec.kt)

## Android

The minimum level of support for Android is 26 as [Base64](https://developer.android.com/reference/java/util/Base64) is being used.

## Creating a JWT

```kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ semver {
featureBranchRegex(listOf("[a-zA-Z\\-_0-9]+\\/sc-\\d+\\/[a-zA-Z\\-_0-9]+"))
findProperty("semver.overrideVersion")?.toString()?.let { overrideVersion(it) }

main {
scope(findProperty("semver.main.scope")?.toString() ?: "patch")
stage(findProperty("semver.main.stage")?.toString() ?: "final")
currentBranch {
scope(findProperty("semver.currentBranch.scope")?.toString())
stage(findProperty("semver.currentBranch.stage")?.toString())
}
}

group = "io.github.nefilim.kjwt"
version = semver.version()
version = semver.version.value

configure<com.adarshr.gradle.testlogger.TestLoggerExtension> {
theme = com.adarshr.gradle.testlogger.theme.ThemeType.STANDARD
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ githubRelease {
// You get this from your user settings > developer settings > Personal Access Tokens
owner("nefilim") // default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai"
repo("kjwt") // by default this is set to your project name
tagName(semver.versionTagName()) // by default this is set to "v${project.version}"
tagName(semver.versionTagName) // by default this is set to "v${project.version}"
targetCommitish("main") // by default this is set to "master"
body(changelog())
draft(false) // by default this is false
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/io/github/nefilim/kjwt/JWT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface JWTClaims {
fun claimValueAsLong(name: String): Option<Long>
fun claimValueAsBoolean(name: String): Option<Boolean>
fun claimValueAsList(name: String): List<String>
fun claimNames(): Set<String>

fun keyID(): Option<JWTKeyID>
fun issuer(): Option<String>
Expand Down Expand Up @@ -172,6 +173,7 @@ class JWT<T: JWSAlgorithm> private constructor(
override fun claimValueAsLong(name: String): Option<Long> = Option.fromNullable(claimSet[name]?.jsonPrimitive?.longOrNull)
override fun claimValueAsBoolean(name: String): Option<Boolean> = Option.fromNullable(claimSet[name]?.jsonPrimitive?.booleanOrNull)
override fun claimValueAsList(name: String): List<String> = claimSet[name]?.jsonArray?.mapNotNull { (it as JsonPrimitive).contentOrNull?.trim() } ?: emptyList()
override fun claimNames(): Set<String> = claimSet.keys

override fun keyID(): Option<JWTKeyID> = Option.fromNullable(header.keyID)
override fun issuer(): Option<String> = claimValue("iss")
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ google-kms = "0.94.0"
gradle-github-release = "2.2.12"
gradle-nexus-publish = "1.1.0"
gradle-protobuf-plugin = "0.8.18"
gradle-semver = "0.0.24"
gradle-semver = "0.0.27"
gradle-tasktree = "2.1.0"
gradle-testlogger = "3.1.0"
gradle-versions = "0.39.0"
Expand Down

0 comments on commit 50c671f

Please sign in to comment.