EncryptGatewayCredentials#216
Conversation
Script that creates a few functions to encrypt different types of credentials to use with the Power BI Gateway APIs
| # 09/03/2023 | ||
| # | ||
| # **Notes** | ||
| # Script created based on the code here: |
There was a problem hiding this comment.
I would write "based on the article here" instead
| # https://endjin.com/blog/2020/12/how-to-update-credentials-for-an-on-prem-power-bi-data-source-using-powershell | ||
| # | ||
| # You will need to run this script at least once to validate the libraries are present in your system | ||
| # After this, you will only need to run the "CreateDatasource" script as it will load this in memory |
There was a problem hiding this comment.
"CreateDatasource or UpdateGatewayDatasource" would be more accurate, right?
VsabGit
left a comment
There was a problem hiding this comment.
I glanced over the code, but in general had implicit assumption, that the code itself didn't change since we tested it together.
I looked more on the wording and comments in the code.
| [string]$GatewayModulus | ||
| ) | ||
|
|
||
| # Create the objects to perform the necessary encryption on the credentials. Again, since I'm using basic credentials, I'm constructing a new BasicCredentials class. Other classes can be found here: https://github.com/microsoft/PowerBI-CSharp/tree/bf7cdf047a0218f7a8555fa7966445812a043955/sdk/PowerBI.Api/Extensions/Models/Credentials |
There was a problem hiding this comment.
"For basic credentials we construct a new BasicCredentials class"...
| $credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj) | ||
| $basicCreds = [Microsoft.PowerBI.Api.Models.Credentials.BasicCredentials]::new($username, $PasswordAsString) | ||
|
|
||
| # Construct the CredentialDetails object. The resulting "Credentials" property on this object will have been encrypted appropriately, ready for use in the request payload. |
There was a problem hiding this comment.
"will be encrypted appropriately"
| [string]$GatewayModulus | ||
| ) | ||
|
|
||
| # Create the objects to perform the necessary encryption on the credentials. Again, since I'm using basic credentials, I'm constructing a new BasicCredentials class. Other classes can be found here: https://github.com/microsoft/PowerBI-CSharp/tree/bf7cdf047a0218f7a8555fa7966445812a043955/sdk/PowerBI.Api/Extensions/Models/Credentials |
There was a problem hiding this comment.
Fix to say "windows credentials" and "WindowsCredentials", other than that same as comment above (line 64).
| $credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj) | ||
| $WindowsCreds = [Microsoft.PowerBI.Api.Models.Credentials.WindowsCredentials]::new($username, $PasswordAsString) | ||
|
|
||
| # Construct the CredentialDetails object. The resulting "Credentials" property on this object will have been encrypted appropriately, ready for use in the request payload. |
There was a problem hiding this comment.
same as comment in line 69.
| [string]$GatewayModulus | ||
| ) | ||
|
|
||
| # Create the objects to perform the necessary encryption on the credentials. Again, since I'm using basic credentials, I'm constructing a new BasicCredentials class. Other classes can be found here: https://github.com/microsoft/PowerBI-CSharp/tree/bf7cdf047a0218f7a8555fa7966445812a043955/sdk/PowerBI.Api/Extensions/Models/Credentials |
There was a problem hiding this comment.
Fix to say "anonymous credentials" and "AnonymousCredentials", other than that same as comment above (line 64).
| $credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj) | ||
| $AnonymousCreds = [Microsoft.PowerBI.Api.Models.Credentials.AnonymousCredentials]::new() | ||
|
|
||
| # Construct the CredentialDetails object. The resulting "Credentials" property on this object will have been encrypted appropriately, ready for use in the request payload. |
There was a problem hiding this comment.
same as comment in line 69.
| [string]$GatewayModulus | ||
| ) | ||
|
|
||
| # Create the objects to perform the necessary encryption on the credentials. Again, since I'm using basic credentials, I'm constructing a new BasicCredentials class. Other classes can be found here: https://github.com/microsoft/PowerBI-CSharp/tree/bf7cdf047a0218f7a8555fa7966445812a043955/sdk/PowerBI.Api/Extensions/Models/Credentials |
There was a problem hiding this comment.
Fix to say "OAuth credentials" and "OAuth2Credentials", other than that same as comment above (line 64).
| $credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj) | ||
| $Oauth2Creds = [Microsoft.PowerBI.Api.Models.Credentials.OAuth2Credentials]::new($OauthToken) | ||
|
|
||
| # Construct the CredentialDetails object. The resulting "Credentials" property on this object will have been encrypted appropriately, ready for use in the request payload. |
There was a problem hiding this comment.
same as comment in line 69.
| [string]$GatewayModulus | ||
| ) | ||
|
|
||
| # Create the objects to perform the necessary encryption on the credentials. Again, since I'm using basic credentials, I'm constructing a new BasicCredentials class. Other classes can be found here: https://github.com/microsoft/PowerBI-CSharp/tree/bf7cdf047a0218f7a8555fa7966445812a043955/sdk/PowerBI.Api/Extensions/Models/Credentials |
There was a problem hiding this comment.
Fix to say "key credentials" and "KeyCredentials", other than that same as comment above (line 64).
| $credentialsEncryptor = [Microsoft.PowerBI.Api.Extensions.AsymmetricKeyEncryptor]::new($gatewayKeyObj) | ||
| $KeyCreds = [Microsoft.PowerBI.Api.Models.Credentials.KeyCredentials]::new($Key) | ||
|
|
||
| # Construct the CredentialDetails object. The resulting "Credentials" property on this object will have been encrypted appropriately, ready for use in the request payload. |
There was a problem hiding this comment.
same as comment in line 69.
Script that creates a few functions to encrypt different types of credentials to use with the Power BI Gateway APIs