-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eabd784
commit de557ed
Showing
8 changed files
with
66 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package de.solugo.oidc | ||
|
||
import org.springframework.web.util.UriComponentsBuilder | ||
import org.springframework.web.server.ServerWebExchange | ||
|
||
interface ConfigurationProvider { | ||
fun provide(builder: UriComponentsBuilder): Map<String, Any> | ||
} | ||
fun provide(exchange: ServerWebExchange): Map<String, Any> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
package de.solugo.oidc | ||
|
||
import de.solugo.oidc.util.uri | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.web.server.ServerWebExchange | ||
import org.springframework.web.util.UriComponentsBuilder | ||
|
||
@ConfigurationProperties("server") | ||
data class ServerProperties( | ||
val publicUrl: String? = null, | ||
val claims: Map<String, Any?> = emptyMap(), | ||
) | ||
) { | ||
fun ServerWebExchange.issuerUri( | ||
block: UriComponentsBuilder.() -> Unit, | ||
) = uri(publicUrl ?: request.uri.toString(), block) | ||
} |
19 changes: 13 additions & 6 deletions
19
src/main/kotlin/de/solugo/oidc/controller/ConfigurationController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
package de.solugo.oidc.controller | ||
|
||
import de.solugo.oidc.ConfigurationProvider | ||
import de.solugo.oidc.ServerProperties | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.util.UriComponentsBuilder | ||
import org.springframework.web.server.ServerWebExchange | ||
|
||
@RestController | ||
class ConfigurationController( | ||
private val configurationProviders: List<ConfigurationProvider>, | ||
private val properties: ServerProperties, | ||
) { | ||
|
||
@GetMapping(".well-known/openid-configuration") | ||
fun configuration(builder: UriComponentsBuilder) = buildMap { | ||
put("issuer", builder.replacePath("/").toUriString()) | ||
configurationProviders.forEach { | ||
putAll(it.provide(builder)) | ||
fun configuration(exchange: ServerWebExchange) = with(properties) { | ||
buildMap { | ||
put("issuer", exchange.issuerUri { | ||
replacePath("/") | ||
}) | ||
configurationProviders.forEach { | ||
putAll(it.provide(exchange)) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package de.solugo.oidc.util | ||
|
||
import org.springframework.web.util.UriComponentsBuilder | ||
import java.util.* | ||
|
||
fun uuid(value: String? = null) = when { | ||
value != null -> UUID.nameUUIDFromBytes(value.toByteArray()).toString() | ||
else -> UUID.randomUUID().toString() | ||
} | ||
|
||
fun uri(uri: String, block: UriComponentsBuilder.() -> Unit) = UriComponentsBuilder.fromUriString(uri).run { | ||
block() | ||
toUriString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters