Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Identity Provider' to PBICloudDataset connection string #659

Merged
merged 2 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Infrastructure/Helpers/ConnectionStringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ internal static class ConnectionStringHelper
//private const string UseEncryptionForDataKey = "Use Encryption for Data";
private const string ApplicationNameKey = "Application Name";
private const string ConnectTimeoutKey = "Connect Timeout";
private const string IdentityProviderKey = "Identity Provider";

private const string ProviderMsolapValue = "MSOLAP";
private const string IntegratedSecuritySspiValue = "SSPI";
private const string IntegratedSecurityClaimsTokenValue = "ClaimsToken";
private const string PersistSecurityInfoValue = "False"; // 'False' here is used as a best practice in order to discard security-sensitive information after the connection has been opened
private const string PersistSecurityInfoValue = "True";

public static string BuildFor(IPEndPoint endPoint)
{
Expand Down Expand Up @@ -83,6 +84,7 @@ public static string BuildFor(PBICloudDataset dataset, string accessToken)
// https://docs.microsoft.com/en-us/power-bi/admin/service-premium-connect-tools#duplicate-dataset-name

BravoUnexpectedException.ThrowIfNull(dataset.WorkspaceName);
BravoUnexpectedException.ThrowIfNull(dataset.IdentityProvider);
BravoUnexpectedException.ThrowIfNull(dataset.ExternalServerName);
BravoUnexpectedException.ThrowIfNull(dataset.ExternalDatabaseName);
BravoUnexpectedException.ThrowIfNull(accessToken);
Expand All @@ -100,7 +102,7 @@ public static string BuildFor(PBICloudDataset dataset, string accessToken)
};
var serverName = serverNameBuilder.Uri.AbsoluteUri;
var databaseName = dataset.ExternalDatabaseName;
var connectionString = Build(serverName, databaseName, accessToken);
var connectionString = Build(serverName, databaseName, accessToken, dataset.IdentityProvider);

return connectionString.ToProtectedString();
}
Expand All @@ -112,18 +114,19 @@ public static string BuildFor(PBICloudDataset dataset, string accessToken)
}
else
{
BravoUnexpectedException.ThrowIfNull(dataset.IdentityProvider);
BravoUnexpectedException.ThrowIfNull(dataset.ExternalServerName);
BravoUnexpectedException.ThrowIfNull(dataset.ExternalDatabaseName);
BravoUnexpectedException.ThrowIfNull(accessToken);

var serverName = dataset.ExternalServerName;
var databaseName = dataset.ExternalDatabaseName;
var connectionString = Build(serverName, databaseName, accessToken);
var connectionString = Build(serverName, databaseName, accessToken, dataset.IdentityProvider);

return connectionString.ToProtectedString();
}

static string Build(string serverName, string databaseName, string accessToken)
static string Build(string serverName, string databaseName, string accessToken, string identityProvider)
{
var builder = new OleDbConnectionStringBuilder()
{
Expand All @@ -132,6 +135,7 @@ static string Build(string serverName, string databaseName, string accessToken)
{ InitialCatalogKey, databaseName },
{ IntegratedSecurityKey, IntegratedSecurityClaimsTokenValue },
{ PersistSecurityInfoKey, PersistSecurityInfoValue },
{ IdentityProviderKey, identityProvider },
{ PasswordKey, accessToken }, // The Analysis Services client libraries automatically add the auth-scheme value "Bearer" to the access token
{ ApplicationNameKey, AppEnvironment.ApplicationInstanceUniqueName }
};
Expand Down
8 changes: 8 additions & 0 deletions src/Infrastructure/Models/PBICloud/PBICloudEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class PBICloudEnvironment: IPBICloudEnvironment
[JsonPropertyName("clusterEndpoint")]
public string? ClusterEndpoint { get; set; }

[JsonPropertyName("identityProvider")]
public string? IdentityProvider => $"{AzureADAuthority}, {AzureADResource}, {AzureADClientId}";

[JsonIgnore]
public bool IsMicrosoftInternal => Type == PBICloudEnvironmentType.Custom && Name.EqualsI(PBICloudEnvironmentTypeExtensions.PpeCloudName);

Expand Down Expand Up @@ -145,6 +148,11 @@ public interface IPBICloudEnvironment
/// </summary>
string? ClusterEndpoint { get; set; }

/// <summary>
/// MSOLAP OLEDB provider 'Identity Provider'
/// </summary>
string? IdentityProvider { get; }

[JsonIgnore]
bool IsMicrosoftInternal { get; }

Expand Down
4 changes: 4 additions & 0 deletions src/Models/PBICloudDataset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class PBICloudDataset : IDataModel<PBICloudDataset>
[JsonPropertyName("externalDatabaseName")]
public string? ExternalDatabaseName { get; set; }

[JsonPropertyName("identityProvider")]
public string? IdentityProvider { get; set; }

[JsonPropertyName("name")]
public string? DisplayName { get; set; }

Expand Down Expand Up @@ -150,6 +153,7 @@ internal static PBICloudDataset CreateFrom(IPBICloudEnvironment environment, Clo
DatabaseName = cloudModel.DBName,
ExternalServerName = null,
ExternalDatabaseName = null,
IdentityProvider = environment.IdentityProvider,
DisplayName = cloudModel.DisplayName,
Description = cloudModel.Description,
Owner = $"{ cloudModel.CreatorUser?.GivenName } { cloudModel.CreatorUser?.FamilyName }",
Expand Down