Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class CallRouter(

callContext.redirect(queryParameters["redirect_uri"] + "?code=${redirect.codeToken}$stateQueryParameter")
} catch (unverifiedIdentityException: InvalidIdentityException) {
authorizer.failedAuthentication()
callContext.respondStatus(STATUS_UNAUTHORIZED)
authorizer.failedAuthentication()
}
}

Expand Down
34 changes: 34 additions & 0 deletions kotlin-oauth2-server-sparkjava/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kotlin-oauth2-server</artifactId>
<groupId>nl.myndocs</groupId>
<version>0.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>kotlin-oauth2-server-sparkjava</artifactId>

<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>nl.myndocs</groupId>
<artifactId>kotlin-oauth2-server-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nl.myndocs.oauth2.sparkjava

import nl.myndocs.oauth2.config.ConfigurationBuilder
import nl.myndocs.oauth2.sparkjava.request.SparkjavaCallContext
import spark.Spark.get
import spark.Spark.post

object Oauth2Server {
fun configureOauth2Server(configurationCallback: ConfigurationBuilder.Configuration.() -> Unit) {
val configuration = ConfigurationBuilder.build(configurationCallback)

val callRouter = configuration.callRouter

post(callRouter.tokenEndpoint) { req, res ->
val sparkjavaCallContext = SparkjavaCallContext(req, res)
callRouter.route(sparkjavaCallContext, configuration.authorizerFactory(sparkjavaCallContext))

res.body()
}


get(callRouter.authorizeEndpoint) { req, res ->
val sparkjavaCallContext = SparkjavaCallContext(req, res)
callRouter.route(sparkjavaCallContext, configuration.authorizerFactory(sparkjavaCallContext))

res.body()
}

get(callRouter.userInfoEndpoint) { req, res ->
val sparkjavaCallContext = SparkjavaCallContext(req, res)
callRouter.route(sparkjavaCallContext, configuration.authorizerFactory(sparkjavaCallContext))

res.body()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nl.myndocs.oauth2.sparkjava.json

import com.google.gson.Gson

object JsonMapper {
private val gson = Gson()

fun toJson(content: Any) = gson.toJson(content)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package nl.myndocs.oauth2.sparkjava.request

import nl.myndocs.oauth2.request.CallContext
import nl.myndocs.oauth2.sparkjava.json.JsonMapper
import spark.Request
import spark.Response

class SparkjavaCallContext(val request: Request, val response: Response) : CallContext {
override val path: String = request.pathInfo()
override val method: String = request.requestMethod()
override val headers: Map<String, String> = request.headers()
.map { it.toLowerCase() to request.headers(it) }
.toMap()

override val queryParameters: Map<String, String> = request.queryParams()
.map { it.toLowerCase() to request.queryParams(it) }
.toMap()

override val formParameters: Map<String, String> = queryParameters

override fun respondStatus(statusCode: Int) {
response.status(statusCode)
response.body("")
}

override fun respondHeader(name: String, value: String) {
response.header(name, value)
}

override fun respondJson(content: Any) {
response.body(JsonMapper.toJson(content))
}

override fun redirect(uri: String) {
response.redirect(uri)
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>kotlin-oauth2-server-identity-inmemory</module>
<module>kotlin-oauth2-server-token-store-inmemory</module>
<module>kotlin-oauth2-server-javalin</module>
<module>kotlin-oauth2-server-sparkjava</module>
</modules>

<dependencies>
Expand Down