Skip to content

Commit 55f25b4

Browse files
authored
Merge pull request #100260 from ekote/patch-1
ADAL to MSAL migration - update apache-spark-sql-connector.md
2 parents 2130ef0 + 9e27622 commit 55f25b4

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

articles/synapse-analytics/spark/data-sources/apache-spark-sql-connector.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
title: Azure SQL and SQL Server
33
description: This article provides information on how to use the connector for moving data between Azure MS SQL and serverless Apache Spark pools.
44
services: synapse-analytics
5-
author: midesa
6-
ms.author: midesa
5+
author: eskot
6+
ms.author: eskot
77
ms.service: synapse-analytics
88
ms.topic: overview
99
ms.subservice: spark
@@ -30,6 +30,8 @@ dbname = "<< database name >>"
3030
url = servername + ";" + "databaseName=" + dbname + ";"
3131
dbtable = "<< table name >> "
3232
user = "<< username >>"
33+
principal_client_id = "<< service principal client id >>"
34+
principal_secret = "<< service principal secret ho>>"
3335
password = mssparkutils.credentials.getSecret('azure key vault name','secret name')
3436
```
3537

@@ -87,20 +89,31 @@ except ValueError as error :
8789

8890
### Python example with service principal
8991
```python
90-
import adal
92+
import msal
9193

9294
# Located in App Registrations from Azure Portal
9395
tenant_id = "<< tenant id >> "
9496

9597
# Located in App Registrations from Azure Portal
9698
resource_app_id_url = "https://database.windows.net/"
9799

100+
# Define scope of the Service for the app registration before requesting from AAD
101+
scope ="https://database.windows.net/.default"
102+
98103
# Authority
99-
authority = "https://login.windows.net/" + tenant_id
104+
authority = "https://login.microsoftonline.net/" + tenant_id
105+
106+
# Get service principal
107+
service_principal_id = mssparkutils.credentials.getSecret('azure key vault name','principal_client_id')
108+
service_principal_secret = mssparkutils.credentials.getSecret('azure key vault name','principal_secret')
109+
110+
111+
context = msal.ConfidentialClientApplication(
112+
service_principal_id, service_principal_secret, authority
113+
)
100114

101-
context = adal.AuthenticationContext(authority)
102-
token = context.acquire_token_with_client_credentials(resource_app_id_url, service_principal_id, service_principal_secret)
103-
access_token = token["accessToken"]
115+
token = app.acquire_token_silent([scope])
116+
access_token = token["access_token"]
104117

105118
jdbc_df = spark.read \
106119
.format("com.microsoft.sqlserver.jdbc.spark") \

0 commit comments

Comments
 (0)