Skip to content

Commit

Permalink
fix: naughty IDEA tried to use wildcard imports
Browse files Browse the repository at this point in the history
  • Loading branch information
kimtore committed Nov 1, 2024
1 parent 0b918cc commit 63a3644
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
35 changes: 20 additions & 15 deletions wonderwalled-idporten/src/main/kotlin/io/nais/TexasClient.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package io.nais

import com.fasterxml.jackson.annotation.JsonProperty
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.nais.common.defaultHttpClient

const val PROVIDER_MASKINPORTEN = "maskinporten"

data class TexasTokenRequest(
val target: String,

@JsonProperty("identity_provider")
val identityProvider: String,
)
Expand All @@ -29,13 +30,17 @@ class TexasClient(
private val config: Configuration.Texas,
private val httpClient: HttpClient = defaultHttpClient(),
) {
suspend fun token(target: String) = httpClient.post(config.texasTokenEndpoint) {
contentType(ContentType.Application.Json)
setBody(TexasTokenRequest(target, PROVIDER_MASKINPORTEN))
}.body<TexasTokenResponse>()

suspend fun introspect(accessToken: String) = httpClient.post(config.texasIntrospectionEndpoint) {
contentType(ContentType.Application.Json)
setBody(TexasIntrospectionRequest(accessToken))
}.body<String>()
}
suspend fun token(target: String) =
httpClient
.post(config.texasTokenEndpoint) {
contentType(ContentType.Application.Json)
setBody(TexasTokenRequest(target, PROVIDER_MASKINPORTEN))
}.body<TexasTokenResponse>()

suspend fun introspect(accessToken: String) =
httpClient
.post(config.texasIntrospectionEndpoint) {
contentType(ContentType.Application.Json)
setBody(TexasIntrospectionRequest(accessToken))
}.body<String>()
}
36 changes: 22 additions & 14 deletions wonderwalled-idporten/src/main/kotlin/io/nais/Wonderwalled.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package io.nais

import com.auth0.jwk.JwkProviderBuilder
import io.ktor.client.plugins.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.auth.jwt.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.statement.readBytes
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
import io.ktor.server.application.Application
import io.ktor.server.auth.authenticate
import io.ktor.server.auth.authentication
import io.ktor.server.auth.jwt.JWTPrincipal
import io.ktor.server.auth.jwt.jwt
import io.ktor.server.cio.CIO
import io.ktor.server.engine.embeddedServer
import io.ktor.server.request.host
import io.ktor.server.request.uri
import io.ktor.server.response.respond
import io.ktor.server.response.respondBytes
import io.ktor.server.response.respondRedirect
import io.ktor.server.routing.get
import io.ktor.server.routing.route
import io.ktor.server.routing.routing
import io.nais.common.bearerToken
import io.nais.common.commonSetup
import io.nais.common.getTokenInfo
Expand Down Expand Up @@ -104,10 +112,10 @@ fun Application.wonderwalled(config: Configuration) {
get("maskinporten") {
call.respond(
texasClient.introspect(
texasClient.token(call.request.queryParameters["target"] ?: "nav:test/api").accessToken
)
texasClient.token(call.request.queryParameters["target"] ?: "nav:test/api").accessToken,
),
)
}
}
}
}
}

0 comments on commit 63a3644

Please sign in to comment.