メインコンテンツまでスキップ

認証

Reveal SDK を使用すると、認証プロバイダーを使用し、そのプロバイダーを Reveal SDK に登録することで、ユーザー名 / パスワードおよびベアラー トークン認証資格情報などのさまざまな認証方法をデータ ソースに提供できます。

認証プロバイダーは、認証資格情報を要求しているデータ ソースを確認し、その特定のデータ ソースの正しい認証資格情報を返すために使用されます。

手順 1 - 認証プロバイダーを作成します。

public class AuthenticationProvider: IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
...
}
}

手順 2 - 認証プロバイダーを Reveal SDK に登録します。

builder.Services.AddControllers().AddReveal( builder =>
{
builder.AddAuthenticationProvider<AuthenticationProvider>();
});

ユーザー名/パスワード認証

データ ソースがユーザー名とパスワードの使用を要求する場合、RVUsernamePasswordDataSourceCredential クラスのインスタンスを返す必要があります。RVUsernamePasswordDataSourceCredential クラスは、ユーザー名パスワード、およびオプションでドメインを定義するコンストラクターのオーバーロードを提供します。

public class AuthenticationProvider: IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;
if (dataSource is RVPostgresDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("username", "password");
}
else if (dataSource is RVSqlServerDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential("username", "password", "domain");
}
return Task.FromResult<IRVDataSourceCredential>(userCredential);
}
}

データ ソースが認証なしで匿名ログインを使用している場合、空のコンストラクターで RVUsernamePasswordDataSourceCredential を使用できます。

if (dataSource is RVSqlServerDataSource)
{
userCredential = new RVUsernamePasswordDataSourceCredential();
}

RVUsernamePasswordDataSourceCredential は、以下のデータ ソースでサポートされます。

  • Amazon Redshift
  • Microsoft Analysis Services サーバー
  • Microsoft Dynamics CRM (オンプレミスおよびオンライン)
  • Microsoft SQL Server
  • MySQL
  • OData サービス
  • Oracle
  • PostgreSQL
  • REST サービス
  • Snowflake
  • Sybase
  • ウェブ リソース

ベアラー トークン認証

データ ソースがセキュリティ トークンの使用を要求する場合、RVBearerTokenDataSourceCredential クラスのインスタンスを返す必要があります。RVBearerTokenDataSourceCredential クラスは、トークンユーザー ID を定義するコンストラクターのオーバーロードを提供します。

public class AuthenticationProvider: IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;
if (dataSource is RVGoogleDriveDataSource)
{
userCredential = new RVBearerTokenDataSourceCredential("token", "userid");
}
return Task.FromResult<IRVDataSourceCredential>(userCredential);
}
}

RVBearerTokenDataSourceCredential は、以下のデータ ソースでサポートされます。

  • Box
  • Databricks
  • Dropbox
  • Google アナリティクス
  • Google Big Query
  • Google Drive
  • Microsoft SQL Server
  • OData サービス
  • OneDrive
  • REST サービス
  • SharePoint オンライン
  • Snowflake
  • ウェブ リソース

Microsoft Entra ID 認証

Microsoft Entra ID (旧 Azure Active Directory) を使用して、Entra ID 認証をサポートするデータ ソース (Microsoft SQL Server など) のベアラー トークンを取得できます。取得したトークンは、RVBearerTokenDataSourceCredential を使用して Reveal SDK に渡されます。

備考

この例では、.NET 用の Microsoft Authentication Library (MSAL) を使用しています。この方法を使用する前に、Microsoft Entra ID でアプリケーションを登録し、適切なデータベース権限を付与する必要があります。

手順 1 - Microsoft.Identity.Client NuGet パッケージをインストールします。

dotnet add package Microsoft.Identity.Client

手順 2 - Entra ID からトークンを取得し、RVBearerTokenDataSourceCredential として返す認証プロバイダーを作成します。

public class AuthenticationProvider : IRVAuthenticationProvider
{
public async Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext,
RVDashboardDataSource dataSource)
{
if (dataSource is RVSqlServerDataSource)
{
var token = await GetEntraTokenAsync("https://database.windows.net/.default");
return new RVBearerTokenDataSourceCredential(token, "myaccount@mydomain.com");
}

return new RVUsernamePasswordDataSourceCredential();
}

private static readonly string ClientId = "your-client-id";
private static readonly string ClientSecret = "your-client-secret";
private static readonly string TenantId = "your-tenant-id";

private static async Task<string> GetEntraTokenAsync(string scope)
{
var app = ConfidentialClientApplicationBuilder
.Create(ClientId)
.WithClientSecret(ClientSecret)
.WithAuthority(AzureCloudInstance.AzurePublic, TenantId)
.Build();

var result = await app
.AcquireTokenForClient(new[] { scope })
.ExecuteAsync();

return result.AccessToken;
}
}
注記

your-client-idyour-client-secretyour-tenant-id を Entra ID アプリ登録の値に置き換えてください。スコープ値 https://database.windows.net/.default は Azure SQL Server に固有です。他のデータ ソースでは異なるスコープが必要になる場合があります。

Microsoft Entra ID 認証は、以下のデータ ソースでサポートされます。

  • Microsoft SQL Server

キーペア認証

データ ソースがキーペア認証を必要とする場合、RVKeyPairDataSourceCredential クラスのインスタンスを返す必要があります。RVKeyPairDataSourceCredential クラスは、ユーザー暗号化されていない RSA 秘密キーを定義するコンストラクターのオーバーロードを提供します。

public class AuthenticationProvider: IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;
if (dataSource is RVSnowflakeDataSource)
{
userCredential = new RVKeyPairDataSourceCredential("user", "unencrypted rsa-key");
}
return Task.FromResult<IRVDataSourceCredential>(userCredential);
}
}

RVKeyPairDataSourceCredential は、以下のデータ ソースでサポートされます。

  • Snowflake

Amazon Web Services

データ ソースが Amazon Web Services (AWS) を使用している場合は、RVAmazonWebServicesCredentials クラスのインスタンスを返す必要があります。RVAmazonWebServicesCredentials クラスは、keysecret を定義するためのコンストラクターのオーバーロードを提供します。

public class AuthenticationProvider: IRVAuthenticationProvider
{
public Task<IRVDataSourceCredential> ResolveCredentialsAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
IRVDataSourceCredential userCredential = null;
if (dataSource is RVS3DataSource)
{
userCredential = new RVAmazonWebServicesCredentials("key", "secret");
}
return Task.FromResult<IRVDataSourceCredential>(userCredential);
}
}

RVAmazonWebServicesCredentials は、次のデータ ソースでサポートされています。

  • Amazon Athena
  • Amazon S3