Skip to content

Commit

Permalink
Use DefaultAzureCredentialBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
spenes committed Jan 22, 2024
1 parent 3ed3a43 commit f0fde19
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ import org.apache.kafka.common.security.auth.AuthenticateCallbackHandler
import org.apache.kafka.common.security.oauthbearer.OAuthBearerToken
import org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenCallback

import com.microsoft.azure.credentials.MSICredentials
import com.azure.identity.DefaultAzureCredentialBuilder
import com.azure.core.credential.TokenRequestContext

import com.nimbusds.jwt.JWTParser

class AzureAuthenticationCallbackHandler extends AuthenticateCallbackHandler {

val credentials: MSICredentials = {
val clientId = sys.env.get("AZURE_CLIENT_ID_FOR_EVENT_HUB").orElse(sys.env.get("AZURE_CLIENT_ID"))
val creds = new MSICredentials()
clientId.map(creds.withClientId).getOrElse(creds)
}
val credentials = new DefaultAzureCredentialBuilder().build()

var sbUri: String = ""

Expand Down Expand Up @@ -66,7 +63,9 @@ class AzureAuthenticationCallbackHandler extends AuthenticateCallbackHandler {
}

def getOAuthBearerToken(): OAuthBearerToken = {
val accessToken = credentials.getToken(sbUri)
val reqContext = new TokenRequestContext()
reqContext.addScopes(sbUri)
val accessToken = credentials.getTokenSync(reqContext).getToken
val jwt = JWTParser.parse(accessToken)
val claims = jwt.getJWTClaimsSet

Expand Down
2 changes: 1 addition & 1 deletion project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object BuildSettings {
libraryDependencies ++= Seq(
Dependencies.Libraries.kafkaClients,
Dependencies.Libraries.mskAuth,
Dependencies.Libraries.azureAuth,
Dependencies.Libraries.azureIdentity,

// integration tests dependencies
Dependencies.Libraries.IntegrationTests.specs2,
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object Dependencies {
val thrift = "0.15.0" // force this version to mitigate security vulnerabilities
val tracker = "2.0.0"
val dataDog4s = "0.32.0"
val azureAuth = "1.7.14"
val azureIdentity = "1.11.0"
}

object Libraries {
Expand Down Expand Up @@ -75,7 +75,7 @@ object Dependencies {
val pubsub = "com.google.cloud" % "google-cloud-pubsub" % V.pubsub
val sqs = "com.amazonaws" % "aws-java-sdk-sqs" % V.awsSdk
val sts = "com.amazonaws" % "aws-java-sdk-sts" % V.awsSdk % Runtime // Enables web token authentication https://github.com/snowplow/stream-collector/issues/169
val azureAuth = "com.microsoft.azure" % "azure-client-authentication" % V.azureAuth
val azureIdentity = "com.azure" % "azure-identity" % V.azureIdentity

//common unit tests
val specs2 = "org.specs2" %% "specs2-core" % V.specs2 % Test
Expand Down

0 comments on commit f0fde19

Please sign in to comment.