I am looking for a way to connect to an Azure Database using Service Principal with SCALA.
I want to be able to generate a token and use it in JDBC to connect to the database. Python example:
import adal
# Located in App Registrations from Azure Portal
tenant_id = "<< tenant id >> "
# Located in App Registrations from Azure Portal
resource_app_id_url = "https://database.windows.net/"
# Authority
authority = "https://login.windows.net/" + tenant_id
context = adal.AuthenticationContext(authority)
token = context.acquire_token_with_client_credentials(resource_app_id_url, service_principal_id, service_principal_secret)
access_token = token["accessToken"]
jdbc_df = spark.read \
.format("com.microsoft.sqlserver.jdbc.spark") \
.option("url", url) \
.option("dbtable", dbtable) \
.option("accessToken", access_token) \
.option("encrypt", "true") \
.option("hostNameInCertificate", "*.database.windows.net") \
.load()
Thank you