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

[OAuth2] Initial work on server-side OAuth2 Token Introspection #269 #373

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ lazy val server = (project in file("server")) enablePlugins(JavaAppPackaging) se
ExclusionRule("com.fasterxml.jackson.module"),
ExclusionRule("org.json4s")
),
"com.linecorp.armeria" % "armeria-oauth2" % "1.24.3",
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf" excludeAll(
ExclusionRule("com.fasterxml.jackson.core"),
ExclusionRule("com.fasterxml.jackson.module"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import javax.annotation.Nullable
import scala.collection.JavaConverters._
import scala.util.Try

import com.linecorp.armeria.client.WebClient
import com.linecorp.armeria.common.{HttpData, HttpHeaderNames, HttpHeaders, HttpMethod, HttpRequest, HttpResponse, HttpStatus, MediaType, ResponseHeaders, ResponseHeadersBuilder}
import com.linecorp.armeria.common.auth.OAuth2Token
import com.linecorp.armeria.internal.server.ResponseConversionUtil
import com.linecorp.armeria.server.{Server, ServiceRequestContext}
import com.linecorp.armeria.server.annotation.{ConsumesJson, Default, ExceptionHandler, ExceptionHandlerFunction, Get, Head, Param, Post, ProducesJson}
import com.linecorp.armeria.server.auth.AuthService
import com.linecorp.armeria.server.auth.oauth2.OAuth2TokenIntrospectionAuthorizer
import io.delta.standalone.internal.DeltaCDFErrors
import io.delta.standalone.internal.DeltaCDFIllegalArgumentException
import io.delta.standalone.internal.DeltaDataSource
Expand Down Expand Up @@ -532,6 +534,22 @@ object DeltaSharingService {
})
builder.decorator(authServiceBuilder.newDecorator)
}
if (serverConfig.getTokenAuthorization != null) {
val tokenAuth = serverConfig.getTokenAuthorization
val introspectClient: WebClient = WebClient.of(tokenAuth.tokenInstrospectionUri)
val authServiceBuilder =
AuthService.builder.addOAuth2(
OAuth2TokenIntrospectionAuthorizer.builder(
introspectClient,
tokenAuth.tokenIntrospectionEndpoint
)
.clientCredentials(() => java.util.Map.entry(
tokenAuth.clientId, tokenAuth.clientSecret
))
.build()
)
builder.decorator(authServiceBuilder.newDecorator)
}
builder.build()
}
server.start().get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ case class ServerConfig(
@BeanProperty var version: java.lang.Integer,
@BeanProperty var shares: java.util.List[ShareConfig],
@BeanProperty var authorization: Authorization,
@BeanProperty var tokenAuthorization: TokenAuthorization,
@BeanProperty var ssl: SSLConfig,
@BeanProperty var host: String,
@BeanProperty var port: Int,
Expand Down Expand Up @@ -71,6 +72,7 @@ case class ServerConfig(
version = null,
shares = Collections.emptyList(),
authorization = null,
tokenAuthorization = null,
ssl = null,
host = "localhost",
port = 80,
Expand Down Expand Up @@ -110,6 +112,9 @@ case class ServerConfig(
if (authorization != null) {
authorization.checkConfig()
}
if (tokenAuthorization != null) {
tokenAuthorization.checkConfig()
}
if (ssl != null) {
ssl.checkConfig()
}
Expand Down Expand Up @@ -167,6 +172,37 @@ case class Authorization(@BeanProperty var bearerToken: String) extends ConfigIt
}
}

case class TokenAuthorization(
@BeanProperty var tokenInstrospectionUri: String,
@BeanProperty var tokenIntrospectionEndpoint: String,
@BeanProperty var clientId: String,
@BeanProperty var clientSecret: String)
extends ConfigItem {

def this() {
this(null, null, null, null)
}

override def checkConfig(): Unit = {
if (tokenInstrospectionUri == null) {
throw new IllegalArgumentException(
"'tokenIntrospectionUri' in 'tokenAuthorization' must be provided"
)
}
if (tokenIntrospectionEndpoint == null) {
throw new IllegalArgumentException(
"'tokenIntrospectionEndpoint' in 'tokenAuthorization' must be provided"
)
}
if (clientId == null) {
throw new IllegalArgumentException("'clientId' in 'tokenAuthorization' must be provided")
}
if (clientSecret == null) {
throw new IllegalArgumentException("'clientSecret' in 'tokenAuthorization' must be provided")
}
}
}

case class SSLConfig(
@BeanProperty var selfSigned: Boolean,
// The file of the PEM-format certificate
Expand Down