Forum Discussion

Koni's avatar
Koni
Regular Visitor
3 years ago
Solved

Gateway Datasource with SPN credentials

Hello,   we have a Power BI Data Gateway to connect to our databricks workspace. When we publish a report we need to bind datasets to a gateway and a datasource. This datasource is set up with oa...
  • Koni's avatar
    Koni
    3 years ago

    Indeed, documentation is not clear : "The encryption algorithm. For a cloud data source, specify None. For an on-premises data source, specify RSA-OAEP and use the gateway public key to encrypt the credentials."

    I think "on-premise" means "when you use data gateway". That's why I need to encrypt.

    It finally works with this script :

     

     

    $keyCreds = [Microsoft.PowerBI.Api.Models.Credentials.KeyCredentials]::new($patDatabricks)
    $gatewayKeyObj = [Microsoft.PowerBI.Api.Models.GatewayPublicKey]::new($gateway.publicKey.exponent, $gateway.publicKey.modulus)
    $credEncrypt = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj)
    
    $credentialDetails = [Microsoft.PowerBI.Api.Models.CredentialDetails]::new(
           $keyCreds, 
           [Microsoft.PowerBI.Api.Models.PrivacyLevel]::Organizational, 
           [Microsoft.PowerBI.Api.Models.EncryptedConnection]::Encrypted, 
           $credEncrypt)
    $credentials = $credentialDetails.Credentials
    
    $body = @{
        credentialDetails = @{
            credentialType      = "Key";
            credentials         = $encryptedCredentials;
            encryptedConnection = "Encrypted";
            encryptionAlgorithm = "RSA-OAEP";
            privacyLevel        = "Organizational";
        }
    } | ConvertTo-Json
    
    Invoke-PowerBIRestMethod -Url "gateways/$($gateway.id)/datasources/$($datasourceId)" -Method PATCH -Body $body