@@ -1256,6 +1256,61 @@ module.exports = {
12561256Check [ this recipe] ( /product/auth/recipes/sql-api-ldap ) for an example of
12571257using ` check_sql_auth ` to authenticate requests to the SQL API with LDAP.
12581258
1259+ You can also check for the protocol and the authentication method as follows. This can
1260+ be useful for handling the [ NTLM] [ ref-ntlm ] authentication in the [ DAX API] [ ref-dax-api ]
1261+ and the [ MDX API] [ ref-mdx-api ] :
1262+
1263+ <CodeTabs >
1264+
1265+ ``` python
1266+ from cube import config
1267+ import os
1268+
1269+ @config (' check_sql_auth' )
1270+ def check_sql_auth (req : dict , user_name : str , password : str ) -> dict :
1271+ # Handle NTLM authentication:
1272+ # - for Power BI `runas` command
1273+ # - for Power BI gateway
1274+ if req[' protocol' ] == ' xmla' and req[' method' ] == ' ntlm' :
1275+ if (user_name == os.environ.get(' CUBEJS_SQL_USER' )):
1276+ return {
1277+ ' password' : os.environ.get(' CUBEJS_SQL_PASSWORD' ),
1278+ ' securityContext' : {}
1279+ }
1280+
1281+ return {
1282+ ' password' : os.environ.get(' CUBEJS_SQL_PASSWORD' ),
1283+ ' securityContext' : {}
1284+ }
1285+
1286+ raise Exception (' Access denied' )
1287+ ```
1288+
1289+ ``` javascript
1290+ module .exports = {
1291+ checkSqlAuth : (req , user_name , password ) => {
1292+ // handle ntlm auth scenarios (PBI "runas" command + PBI gateway auth)
1293+ if (req .protocol === ' xmla' && req .method === ' ntlm' ) {
1294+ if (user_name === process .env .CUBEJS_SQL_USER ) {
1295+ return {
1296+ password: process .env .CUBEJS_SQL_PASSWORD ,
1297+ securityContext: {}
1298+ }
1299+ }
1300+
1301+ return {
1302+ password: process .env .CUBEJS_SQL_PASSWORD ,
1303+ securityContext: {}
1304+ }
1305+ }
1306+
1307+ throw new Error (' Access denied' )
1308+ }
1309+ }
1310+ ```
1311+
1312+ </CodeTabs >
1313+
12591314### ` can_switch_sql_user `
12601315
12611316Used in the [ SQL API] [ ref-sql-api ] . Default implementation depends on
@@ -1484,4 +1539,7 @@ If not defined, Cube will lookup for environment variable
14841539[ ref-dap-roles ] : /product/auth/data-access-policies#data-access-roles
14851540[ ref-auth-integration ] : /product/auth#authentication-integration
14861541[ ref-ldap-roles-mapping ] : /product/workspace/sso#user-roles-mapping
1487- [ ref-ldap-integration ] : /product/workspace/sso#ldap-integration
1542+ [ ref-ldap-integration ] : /product/workspace/sso#ldap-integration
1543+ [ ref-dax-api ] : /product/apis-integrations/dax-api
1544+ [ ref-mdx-api ] : /product/apis-integrations/mdx-api
1545+ [ ref-ntlm ] : /product/auth/methods/ntlm
0 commit comments