Skip to content

Commit

Permalink
Merge pull request #69 from Liftric/feat/kotlin-1-9
Browse files Browse the repository at this point in the history
Feat/kotlin 1.9.10
  • Loading branch information
benjohnde authored Oct 26, 2023
2 parents d2a4f23 + de06c8f commit 2043db0
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Build and test (Android, Jvm, Js)
run: region=${{ secrets.region }} clientId=${{ secrets.clientid }} ./gradlew build test jsTest
- name: Build testapp and test request (iOS)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Grant Permission to Execute
run: chmod +x gradlew
- name: New version
Expand Down
91 changes: 63 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.liftric.vault.GetVaultSecretTask
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon
import org.jetbrains.kotlin.gradle.tasks.*

plugins {
id("com.android.library") version libs.versions.android.tools.gradle
kotlin("multiplatform") version libs.versions.kotlin
alias(libs.plugins.kotlin.serialization)
id("com.android.library") version libs.versions.android.tools.gradle
alias(libs.plugins.definitions)
alias(libs.plugins.npm.publishing)
alias(libs.plugins.versioning)
alias(libs.plugins.vault.client)
alias(libs.plugins.kotlin.serialization)
id("maven-publish")
id("signing")
}
Expand All @@ -33,11 +34,12 @@ kotlin {

iosSimulatorArm64()

android {
publishLibraryVariants("debug", "release")
androidTarget() {
publishAllLibraryVariants()
}
jvm()
js(IR) {
generateTypeScriptDefinitions()
browser {
testTask {
useMocha {
Expand All @@ -46,14 +48,19 @@ kotlin {
}
}
binaries.library()
compilations.all {
compileTaskProvider.configure {
compilerOptions.freeCompilerArgs.add("-Xir-minimized-member-names=false")
}
}
}

sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.ktor.client.core)
implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.serialization)
api(libs.ktor.client.core)
api(libs.kotlinx.coroutines)
api(libs.kotlinx.serialization)
}
}
val commonTest by getting {
Expand All @@ -66,15 +73,15 @@ kotlin {
}
val androidMain by getting {
dependencies {
implementation(libs.ktor.client.android)
api(libs.ktor.client.android)
}
}
val jvmMain by getting {
dependencies {
implementation(libs.ktor.client.jvm)
api(libs.ktor.client.jvm)
}
}
val androidTest by getting {
val androidUnitTest by getting {
dependencies {
implementation(libs.roboelectric)
implementation(kotlin("test"))
Expand All @@ -92,7 +99,7 @@ kotlin {
}
val iosMain by getting {
dependencies {
implementation(libs.ktor.client.darwin)
api(libs.ktor.client.darwin)
}
}
val iosTest by getting
Expand All @@ -104,7 +111,7 @@ kotlin {
}
val jsMain by getting {
dependencies {
implementation(libs.ktor.client.js)
api(libs.ktor.client.js)
}
}
val jsTest by getting {
Expand All @@ -122,13 +129,12 @@ kotlin {
}
}

android {
compileSdk = 30

defaultConfig {
minSdk = 21
targetSdk = 30
testInstrumentationRunner = "androidx.test.runner"
configure<LibraryExtension> {
defaultConfig.apply {
compileSdk = 30
minSdkVersion(21)
targetSdkVersion(30)
testInstrumentationRunner = "org.robolectric.RobolectricTestRunner"
}

compileOptions {
Expand All @@ -138,9 +144,19 @@ android {

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
isReturnDefaultValues = true
}
}

namespace = "com.liftric.cognito.idp"

publishing {
multipleVariants {
allVariants()
withJavadocJar()
}
}
}

group = "com.liftric"
Expand Down Expand Up @@ -315,13 +331,15 @@ npmPublish {
named("js") {
packageName.set(project.name)
packageJson {
keywords.set(listOf(
"kotlin",
"cognito",
"identity-provider",
"liftric",
"aws"
))
keywords.set(
listOf(
"kotlin",
"cognito",
"identity-provider",
"liftric",
"aws"
)
)
license.set("MIT")
description.set("Lightweight AWS Cognito Identity Provider client.")
homepage.set("https://github.com/liftric/cognito-idp")
Expand Down Expand Up @@ -352,3 +370,20 @@ vault {
vaultToken.set(System.getenv("VAULT_TOKEN"))
}
}
tasks {
afterEvaluate {
val signingTasks = filter { it.name.startsWith("sign") }
all {
// lets bruteforce this until the plugins play along nicely again

if (name.contains("compile", true) && name.contains("kotlin", true)) {
dependsOn("createJsEnvHack")
}
if (name.startsWith("publish")) {
signingTasks.forEach { signTask ->
dependsOn(signTask)
}
}
}
}
}
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ android.useAndroidX=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4096m
org.gradle.vfs.watch=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.incremental=true
kotlin.incremental.multiplatform=true
kotlin.caching.enabled=true
kotlin.code.style=official
kotlin.js.generate.externals=true
kotlin.native.binary.memoryModel=experimental
kotlin.js.ir.output.granularity=whole-program
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 6 additions & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ dependencyResolutionManagement {

versionCatalogs {
create("libs") {
version("android-tools-gradle", "7.2.0")
version("kotlin", "1.7.10")
version("ktor", "2.1.3")
version("android-tools-gradle", "8.1.0")
version("kotlin", "1.9.10")
version("ktor", "2.3.5")

library("ktor-client-core", "io.ktor", "ktor-client-core").versionRef("ktor")
library("ktor-client-android", "io.ktor", "ktor-client-android").versionRef("ktor")
library("ktor-client-darwin", "io.ktor", "ktor-client-darwin-legacy").versionRef("ktor")
library("ktor-client-jvm", "io.ktor", "ktor-client-java").versionRef("ktor")
library("ktor-client-js", "io.ktor", "ktor-client-js").versionRef("ktor")
library("kotlinx-coroutines", "org.jetbrains.kotlinx", "kotlinx-coroutines-core").version("1.6.1")
library("kotlinx-serialization", "org.jetbrains.kotlinx", "kotlinx-serialization-json").version("1.3.3")
library("kotlinx-coroutines", "org.jetbrains.kotlinx", "kotlinx-coroutines-core").version("1.7.2")
library("kotlinx-serialization", "org.jetbrains.kotlinx", "kotlinx-serialization-json").version("1.5.1")
library("androidx-test-core", "androidx.test", "core").version("1.2.0")
library("roboelectric", "org.robolectric", "robolectric").version("4.5.1")
library("roboelectric", "org.robolectric", "robolectric").version("4.9")
library("opt-java", "com.github.bastiaanjansen", "otp-java").version("1.3.2")

plugin("vault-client", "com.liftric.vault-client-plugin").version("2.0.0")
Expand Down
1 change: 1 addition & 0 deletions src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,23 @@ abstract class AbstractIdentityProviderClientTests {

val associateSoftwareTokenResponse =
provider.associateSoftwareToken(result.AccessToken!!)
val softwareTokenResponse = associateSoftwareTokenResponse.getOrThrow()
println("[Associate software token] softwareTokenResponse=$softwareTokenResponse")
assertTrue(
associateSoftwareTokenResponse.getOrThrow().SecretCode.isNotEmpty(),
softwareTokenResponse.SecretCode.isNotEmpty(),
"SecretCode is missing in Cognito response"
)

generateTotpCode(associateSoftwareTokenResponse.getOrThrow().SecretCode)?.let { code ->
generateTotpCode(softwareTokenResponse.SecretCode)?.let { code ->
println("[Associate software token] generateTotpCode code=$code")
val verificationCodeResponse = provider.verifySoftwareToken(
accessToken = result.AccessToken!!,
friendlyDeviceName = "Association test device",
userCode = code
)
assertEquals("SUCCESS", verificationCodeResponse.getOrThrow().Status, "Failed to verify TOTP token")
val verifySoftwareTokenResponse = verificationCodeResponse.getOrThrow()
println("[Associate software token] verifySoftwareTokenResponse=$verifySoftwareTokenResponse")
assertEquals("SUCCESS", verifySoftwareTokenResponse.Status, "Failed to verify TOTP token")

val setupMfa = provider.setUserMFAPreference(
accessToken = result.AccessToken!!,
Expand All @@ -465,12 +470,17 @@ abstract class AbstractIdentityProviderClientTests {
provider.signOut(result.AccessToken!!)

val signInResponse = provider.signIn(credentials.username, credentials.password).getOrThrow()
println("[Associate software token] signInResponse=$signInResponse")

assertNull(signInResponse.AuthenticationResult, "Should need to respond to challenge")

delay(30000) // Wait until new code gets issued
val delayInMillis: Long = 30000
println("[Associate software token] pre delay (delayInMillis=$delayInMillis")
delay(delayInMillis) // Wait until new code gets issued
println("[Associate software token] post delay")

val newCode = generateTotpCode(associateSoftwareTokenResponse.getOrThrow().SecretCode)!!
val newCode = generateTotpCode(softwareTokenResponse.SecretCode)!!
println("[Associate software token] newCode=$newCode")

val challengeResponse = provider.respondToAuthChallenge(
"SOFTWARE_TOKEN_MFA",
Expand All @@ -480,12 +490,16 @@ abstract class AbstractIdentityProviderClientTests {
),
signInResponse.Session!!
)
val secondSignInResponse = challengeResponse.getOrThrow()
println("[Associate software token] secondSignInResponse=$secondSignInResponse")

assertNull(challengeResponse.getOrThrow().ChallengeName, "Should not need to respond to challenge")
assertNull(secondSignInResponse.ChallengeName, "Should not need to respond to challenge")

deleteUser(challengeResponse.getOrThrow().AuthenticationResult!!.AccessToken!!)
deleteUser(secondSignInResponse.AuthenticationResult!!.AccessToken!!)

delay(30000) // Wait until new code gets issued before next test run
println("[Associate software token] second pre delay (delayInMillis=$delayInMillis")
delay(delayInMillis) // Wait until new code gets issued before next test run
println("[Associate software token] second post delay")
}
}
}
2 changes: 1 addition & 1 deletion src/iosMain/kotlin/com/liftric/cognito/idp/jwt/Base64.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal actual class Base64 {
if (remainder > 0) {
encoded64 = encoded64.padEnd(input.count() + (4 - remainder), '=')
}
return NSData.create(encoded64, 0)?.let {
return NSData.create(encoded64, 0u)?.let {
@Suppress("USELESS_CAST") // false positive inspection: konan fails if the cast is removed
(NSString.create(it, NSUTF8StringEncoding) as String?)
}?: run {
Expand Down
1 change: 0 additions & 1 deletion src/main/AndroidManifest.xml

This file was deleted.

0 comments on commit 2043db0

Please sign in to comment.