Skip to content
Open
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
70 changes: 43 additions & 27 deletions dotnet/examples/VaasExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@ namespace VaasExample;

public static class Program
{
private static string ClientId => Environment.GetEnvironmentVariable("CLIENT_ID") ?? string.Empty;
private static string ClientIdForResourceOwnerPasswordGrant => Environment.GetEnvironmentVariable("VAAS_CLIENT_ID") ?? "vaas-customer";
private static string ClientSecret => Environment.GetEnvironmentVariable("CLIENT_SECRET") ?? string.Empty;
private static string UserName => Environment.GetEnvironmentVariable("VAAS_USER_NAME") ?? string.Empty;
private static string Password => Environment.GetEnvironmentVariable("VAAS_PASSWORD") ?? string.Empty;
private static Uri VaasUrl => new(Environment.GetEnvironmentVariable("VAAS_URL") ??
"wss://gateway.production.vaas.gdatasecurity.de");
private static Uri TokenUrl => new(Environment.GetEnvironmentVariable("TOKEN_URL") ??
"https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token");

public static async Task Main(string[] args)
{
DotNetEnv.Env.TraversePath().Load();
if (args.Contains("UrlScan"))
await UrlScan();
if (args.Contains("FileScan"))
Expand All @@ -42,7 +33,7 @@ private static async Task HashsumScan()

Console.WriteLine($"{verdict.Sha256} is detected as {verdict.Verdict}");
}

private static async Task UrlScan()
{
var vaas = CreateVaas();
Expand All @@ -55,27 +46,52 @@ private static async Task UrlScan()

private static IVaas CreateVaas()
{
// If you got a username and password from us, you can use the GrantType.Password like this
// You may use self registration and create a new username and password for the
// Credentials by yourself like the example above on https://vaas.gdata.de/login
var authenticator = new ResourceOwnerPasswordGrantAuthenticator(
ClientIdForResourceOwnerPasswordGrant,
UserName,
Password,
TokenUrl
);
// // Else if you got a client id and client secret from us, you should use the GrantType.ClientCredentials like this
// var authenticator = new ClientCredentialsGrantAuthenticator(
// ClientId,
// ClientSecret,
// TokenUrl
// );
var clientId = Environment.GetEnvironmentVariable("CLIENT_ID");
var clientIdForResourceOwnerPasswordGrant = Environment.GetEnvironmentVariable("VAAS_CLIENT_ID") ?? "vaas-customer";
var clientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET");
var userName = Environment.GetEnvironmentVariable("VAAS_USER_NAME");
var password = Environment.GetEnvironmentVariable("VAAS_PASSWORD");
var vaasUrl = new Uri(Environment.GetEnvironmentVariable("VAAS_URL") ??
"https://gateway.production.vaas.gdatasecurity.de");
var tokenUrl = new Uri(Environment.GetEnvironmentVariable("TOKEN_URL") ??
"https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token");

IAuthenticator authenticator;
if (userName is not null)
{
if (password is null)
throw new ArgumentNullException("VAAS_PASSWORD", "Password must be set when using Resource Owner Password Grant");
// If you got a username and password from us, you can use the GrantType.Password like this
// You may use self registration and create a new username and password for the
// Credentials by yourself like the example above on https://vaas.gdata.de/login
authenticator = new ResourceOwnerPasswordGrantAuthenticator(
clientIdForResourceOwnerPasswordGrant,
userName,
password,
tokenUrl
);

}
else
{
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new ArgumentNullException("CLIENT_ID or CLIENT_SECRET", "CLIENT_ID and CLIENT_SECRET must be set when using Client Credentials Grant");
}

// Else if you got a client id and client secret from us, you should use the GrantType.ClientCredentials like this
authenticator = new ClientCredentialsGrantAuthenticator(
clientId,
clientSecret,
tokenUrl
);
}

var options = new VaasOptions
{
UseCache = true,
UseHashLookup = true,
VaasUrl = VaasUrl,
VaasUrl = vaasUrl,
Timeout = TimeSpan.FromSeconds(300)
};

Expand Down
5 changes: 3 additions & 2 deletions dotnet/examples/VaasExample/VaasExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GDataCyberDefense.Vaas" Version="8.1.10" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="GDataCyberDefense.Vaas" Version="8.1.11" />
</ItemGroup>

</Project>
Loading