Skip to content

Commit 8855628

Browse files
committed
Initial Commit
0 parents  commit 8855628

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1134
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Project exclude paths
2+
/.gradle/
3+
/build/
4+
/.idea/

build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
plugins {
2+
id 'org.jetbrains.kotlin.jvm' version '1.3.71'
3+
}
4+
5+
group 'com.papsign'
6+
version '0.0-beta.0'
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
14+
implementation 'joda-time:joda-time:2.10.5'
15+
implementation "io.ktor:ktor-server-core:$ktor_version"
16+
implementation "io.ktor:ktor-auth:$ktor_version"
17+
}
18+
19+
compileKotlin {
20+
kotlinOptions.jvmTarget = "1.6"
21+
}
22+
compileTestKotlin {
23+
kotlinOptions.jvmTarget = "1.6"
24+
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kotlin.code.style=official
2+
ktor_version=1.3.1

gradle/wrapper/gradle-wrapper.jar

53.9 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Mar 31 14:19:59 CEST 2020
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
3+
distributionBase=GRADLE_USER_HOME
4+
distributionPath=wrapper/dists
5+
zipStorePath=wrapper/dists
6+
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'KtorOAuthServer'
2+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.papsign.oauth2
2+
3+
import com.papsign.oauth2.token.access.OAuth2AccessToken
4+
import io.ktor.application.ApplicationCall
5+
import io.ktor.response.respond
6+
import org.joda.time.DateTime
7+
import org.joda.time.Seconds
8+
import java.net.URLDecoder
9+
import java.net.URLEncoder
10+
11+
suspend fun OAuth2AccessToken<*, *, *, *>.respondBody(call: ApplicationCall) {
12+
call.respond(makeResponse())
13+
}
14+
15+
fun OAuth2AccessToken<*, *, *, *>.makeResponse(): Map<String, String?> {
16+
return mapOf(
17+
"access_token" to token,
18+
"token_type" to tokenType,
19+
"expires_in" to Seconds.secondsBetween(DateTime.now(), expireDate).seconds.toString(),
20+
"refresh_token" to refreshToken?.token,
21+
"scope" to scopes.joinToString(" ")
22+
)
23+
}
24+
25+
fun encodeQuery(str: String) = URLEncoder.encode(str, "UTF-8")
26+
fun decodeQuery(str: String) = URLDecoder.decode(str, "UTF-8")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.papsign.oauth2.authserver
2+
3+
import com.papsign.oauth2.authserver.authorization.OAuth2AuthorizationHandler
4+
import com.papsign.oauth2.authserver.granter.OAuth2GranterHandler
5+
import com.papsign.oauth2.authserver.module.OAuth2AuthServerModule
6+
import com.papsign.oauth2.authserver.module.OAuth2PathedAuthServerModule
7+
import io.ktor.application.Application
8+
import io.ktor.routing.Routing
9+
import io.ktor.routing.routing
10+
11+
class OAuth2AuthServer(val modules: Set<OAuth2AuthServerModule>)
12+
13+
inline fun oauthServer(accessTokenURL: String, authrizationURL: String, crossinline config: MutableSet<OAuth2AuthServerModule>.()->Unit): OAuth2AuthServer {
14+
val set: MutableSet<OAuth2AuthServerModule> = mutableSetOf(OAuth2AuthorizationHandler(authrizationURL), OAuth2GranterHandler(accessTokenURL))
15+
set.config()
16+
return OAuth2AuthServer(set)
17+
}
18+
19+
fun Routing.oauth2server(server: OAuth2AuthServer) {
20+
server.modules.filterIsInstance<OAuth2PathedAuthServerModule>().forEach {
21+
with(it) {
22+
buildRoute(server)
23+
}
24+
}
25+
}
26+
27+
fun Application.oauth2server(server: OAuth2AuthServer) {
28+
routing {
29+
oauth2server(server)
30+
}
31+
}

0 commit comments

Comments
 (0)