Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ktor 2.0.1 #87

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
hs_err_pid*

.idea
**.iml
**.iml
target
2 changes: 1 addition & 1 deletion oauth2-server-client-inmemory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion oauth2-server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion oauth2-server-hexagon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 3 additions & 3 deletions oauth2-server-http4k/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,13 +15,13 @@
<dependency>
<groupId>org.http4k</groupId>
<artifactId>http4k-core</artifactId>
<version>3.37.1</version>
<version>4.25.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.http4k</groupId>
<artifactId>http4k-server-jetty</artifactId>
<version>3.37.1</version>
<version>4.25.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion oauth2-server-identity-inmemory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
10 changes: 5 additions & 5 deletions oauth2-server-integration-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>oauth2-server-integration-base</artifactId>

<properties>
<jackson.version>2.11.4</jackson.version>
<jackson.databind.version>2.11.4</jackson.databind.version>
<jackson.version>2.13.3</jackson.version>
<jackson.databind.version>2.13.3</jackson.databind.version>
</properties>

<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.1</version>
<version>4.9.3</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<version>5.8.2</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract class BaseIntegrationTest {
val response = client.newCall(request)
.execute()

val values = objectMapper.readMap(response.body()!!.string())
val values = objectMapper.readMap(response.body!!.string())

assertThat(values["access_token"], `is`(notNullValue()))
assertThat(UUID.fromString(values["access_token"] as String), `is`(instanceOf(UUID::class.java)))
Expand Down Expand Up @@ -98,25 +98,31 @@ abstract class BaseIntegrationTest {

response.close()

val body = FormBody.Builder()
val body = response.header("location")!!.asQueryParameters()["code"]?.let {
FormBody.Builder()
.add("grant_type", "authorization_code")
.add("code", response.header("location")!!.asQueryParameters()["code"])
.add("code", it)
.add("redirect_uri", "http://localhost:8080/callback")
.add("client_id", "testapp")
.add("client_secret", "testpass")
.build()
}

val tokenUrl = buildOauthTokenUri()

val tokenRequest = Request.Builder()
val tokenRequest = body?.let {
Request.Builder()
.url(tokenUrl)
.post(body)
.post(it)
.build()
}

val tokenResponse = client.newCall(tokenRequest)
val tokenResponse = tokenRequest?.let {
client.newCall(it)
.execute()
}

val values = objectMapper.readMap(tokenResponse.body()!!.string())
val values = objectMapper.readMap(tokenResponse?.body!!.string())
assertThat(values["access_token"], `is`(notNullValue()))
assertThat(UUID.fromString(values["access_token"] as String), `is`(instanceOf(UUID::class.java)))

Expand All @@ -140,7 +146,7 @@ abstract class BaseIntegrationTest {
val tokenResponse = client.newCall(tokenRequest)
.execute()

val values = objectMapper.readMap(tokenResponse.body()!!.string())
val values = objectMapper.readMap(tokenResponse.body!!.string())
assertThat(values["access_token"], `is`(notNullValue()))
assertThat(UUID.fromString(values["access_token"] as String), `is`(instanceOf(UUID::class.java)))

Expand Down
4 changes: 2 additions & 2 deletions oauth2-server-javalin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.12.0</version>
<version>4.5.0</version>
<scope>provided</scope>
</dependency>

Expand Down
4 changes: 2 additions & 2 deletions oauth2-server-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<version>2.9.0</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions oauth2-server-jwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.5.0</version>
<version>3.19.2</version>
</dependency>
</dependencies>
</project>
44 changes: 36 additions & 8 deletions oauth2-server-ktor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.7.1</version>
<version>0.7.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>oauth2-server-ktor</artifactId>

<properties>
<ktor.version>1.1.2</ktor.version>
<ktor.version>2.0.1</ktor.version>
</properties>

<dependencies>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-core</artifactId>
<artifactId>ktor-server-core-jvm</artifactId>
<version>${ktor.version}</version>
<scope>provided</scope>
</dependency>
Expand All @@ -37,7 +37,7 @@

<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty</artifactId>
<artifactId>ktor-server-netty-jvm</artifactId>
<version>${ktor.version}</version>
<scope>test</scope>
</dependency>
Expand All @@ -47,20 +47,48 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-utils-jvm</artifactId>
<version>${ktor.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-host-common-jvm</artifactId>
<version>${ktor.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>ktor</id>
<url>http://dl.bintray.com/kotlin/ktor</url>
<url>https://kotlin.bintray.com/ktor</url>
</repository>
<repository>
<id>kotlinx</id>
<url>http://dl.bintray.com/kotlin/kotlinx</url>
<url>https://kotlin.bintray.com/kotlinx</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>jitpack</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>ktor-eap</id>
<url>https://maven.pkg.jetbrains.space/public/p/ktor/eap</url>
</repository>
<repository>
<id>ktor-dev</id>
<url>https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev</url>
</repository>
<repository>
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
<id>central1</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
package nl.myndocs.oauth2.ktor.feature

import io.ktor.application.ApplicationCallPipeline
import io.ktor.application.ApplicationFeature
import io.ktor.application.call
import io.ktor.util.AttributeKey
import nl.myndocs.oauth2.config.Configuration
import nl.myndocs.oauth2.config.ConfigurationBuilder
import nl.myndocs.oauth2.ktor.feature.config.KtorConfiguration
import nl.myndocs.oauth2.ktor.feature.request.KtorCallContext
import io.ktor.server.application.*

class Oauth2ServerFeature(configuration: Configuration) {
public class Oauth2ServerFeature(configuration: Configuration) {
val callRouter = configuration.callRouter

companion object Feature : ApplicationFeature<ApplicationCallPipeline, KtorConfiguration, Oauth2ServerFeature> {
public companion object : BaseApplicationPlugin<Application, KtorConfiguration, Oauth2ServerFeature> {
override val key = AttributeKey<Oauth2ServerFeature>("Oauth2ServerFeature")

override fun install(pipeline: ApplicationCallPipeline, configure: KtorConfiguration.() -> Unit): Oauth2ServerFeature {
override fun install(pipeline: Application, configure: KtorConfiguration.() -> Unit): Oauth2ServerFeature {
val ktorConfiguration = KtorConfiguration()
configure(ktorConfiguration)
val configuration = ConfigurationBuilder.build(configure as ConfigurationBuilder.Configuration.() -> Unit, ktorConfiguration)

val configuration =
ConfigurationBuilder.build(configure as ConfigurationBuilder.Configuration.() -> Unit, ktorConfiguration)

val feature = Oauth2ServerFeature(configuration)

pipeline.intercept(ApplicationCallPipeline.Features) {
pipeline.intercept(ApplicationCallPipeline.Plugins) {
val ktorCallContext = KtorCallContext(call)

if (configuration.callRouter.authorizeEndpoint == ktorCallContext.path) {
ktorConfiguration.authenticationCallback(call, feature.callRouter)
}

if (
arrayOf(
configuration.callRouter.tokenEndpoint,
configuration.callRouter.tokenInfoEndpoint
).contains(ktorCallContext.path)
arrayOf(
configuration.callRouter.tokenEndpoint,
configuration.callRouter.tokenInfoEndpoint
).contains(ktorCallContext.path)
) {
feature.callRouter.route(ktorCallContext)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nl.myndocs.oauth2.ktor.feature.config

import io.ktor.application.*
import io.ktor.server.application.*
import nl.myndocs.oauth2.config.ConfigurationBuilder
import nl.myndocs.oauth2.ktor.feature.request.KtorCallContext
import nl.myndocs.oauth2.request.auth.CallContextBasicAuthenticator
Expand Down
Loading