Skip to content

Commit

Permalink
Merge pull request #302 from GDATASoftwareAG/authentication_examples
Browse files Browse the repository at this point in the history
Complete authentication examples
  • Loading branch information
lennartdohmann authored Sep 29, 2023
2 parents 92f8192 + fb9230a commit 77c9858
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
9 changes: 6 additions & 3 deletions dotnet/examples/VaasExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ private static async Task FileScan()
{
Url = VaasUrl,
};
// If you got username + password
var authenticator = new ResourceOwnerPasswordGrantAuthenticator(ClientIdForResourceOwnerPasswordGrant, UserName, Password, TokenUrl);
// else if you got client id and client secret
// If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this
var authenticator = new ResourceOwnerPasswordGrantAuthenticator("vaas-customer", UserName, Password, TokenUrl);
// You may use self registration and create a new username and password for the
// ResourceOwnerPasswordAuthenticator by yourself like the example above on https://vaas.gdata.de/login

// Else if you got a client id and client secret from us, you can use the ClientCredentialsGrantAuthenticator like this
// var authenticator = new ClientCredentialsGrantAuthenticator(
// ClientId,
// ClientSecret,
Expand Down
2 changes: 1 addition & 1 deletion java/examples/VaasExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {

dependencies {
implementation 'org.slf4j:slf4j-nop:2.0.7'
implementation 'de.gdata:vaas:5.2.0'
implementation 'de.gdata:vaas:6.1.0'
}

task fileScan(type: JavaExec) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.gdata.vaasexample;

import de.gdata.vaas.ClientCredentialsGrantAuthenticator;
import de.gdata.vaas.ResourceOwnerPasswordGrantAuthenticator;
import de.gdata.vaas.Vaas;
import de.gdata.vaas.VaasConfig;
import de.gdata.vaas.messages.VerdictRequestAttributes;
import java.net.URI;
import java.nio.file.Path;


public class Authentication {
public static void main(String[] args) throws Exception {
var clientId = System.getenv("CLIENT_ID");
var clientSecret = System.getenv("CLIENT_SECRET");
var userName = System.getenv("VAAS_USER_NAME");
var password = System.getenv("VAAS_PASSWORD");
var scanPath = System.getenv("SCAN_PATH");
var tokenUrl = System.getenv("TOKEN_URL");
if (tokenUrl == null) { tokenUrl = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"; }
var vaasUrl = System.getenv("VAAS_URL");
if (vaasUrl == null) { vaasUrl = "wss://gateway.production.vaas.gdatasecurity.de"; }

// If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this
var authenticator = new ResourceOwnerPasswordGrantAuthenticator(
"vaas-customer",
userName,
password,
new URI(tokenUrl)
);
// You may use self registration and create a new username and password for the
// ResourceOwnerPasswordAuthenticator by yourself like the example above on https://vaas.gdata.de/login

// Else if you got a client id and client secret from us, you can use the ClientCredentialsGrantAuthenticator like this
// var authenticator = new ClientCredentialsGrantAuthenticator(
// clientId,
// clientSecret,
// new URI(tokenUrl)
// );

var config = new VaasConfig(new URI(vaasUrl));
var vaas = new Vaas(config, authenticator);
vaas.connect();

var file = Path.of(scanPath);
var verdictRequestAttributes = new VerdictRequestAttributes();
verdictRequestAttributes.setTenantId("fileTenant");
var verdict = vaas.forFile(file, verdictRequestAttributes);
vaas.disconnect();
System.out.printf("File %s was detected as %s", verdict.getSha256(), verdict.getVerdict());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(String[] args) throws Exception {
vaasUrl = "wss://gateway.production.vaas.gdatasecurity.de";
}

var authenticator = new ClientCredentialsGrantAuthenticator(clientId, clientSecret, tokenUrl);
var authenticator = new ClientCredentialsGrantAuthenticator(clientId, clientSecret, new URI(tokenUrl));
var config = new VaasConfig(
new URI(vaasUrl));
var vaas = new Vaas(config, authenticator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void main(String[] args) throws Exception {
vaasUrl = "wss://gateway.production.vaas.gdatasecurity.de";
}

var authenticator = new ClientCredentialsGrantAuthenticator(clientId, clientSecret, tokenUrl);
var authenticator = new ClientCredentialsGrantAuthenticator(clientId, clientSecret, new URI(tokenUrl));
var config = new VaasConfig(new URI(vaasUrl));
var vaas = new Vaas(config, authenticator);
vaas.connect();
Expand Down
6 changes: 3 additions & 3 deletions php/examples/VaasExample/AuthenticationExamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this
if ($USE_RESOURCE_OWNER_PASSWORD_GRANT_AUTHENTICATOR){
$authenticator = new ResourceOwnerPasswordGrantAuthenticator(
getenv("VAAS_CLIENT_ID"),
"vaas-customer",
getenv("VAAS_USER_NAME"),
getenv("VAAS_PASSWORD"),
getenv("TOKEN_URL")
);
}
// If you got a client id with a link you may use self registration and create a new username and password for the
// ResourceOwnerPasswordAuthenticator by yourself like the example above.
// You may use self registration and create a new username and password for the
// ResourceOwnerPasswordAuthenticator by yourself like the example above on https://vaas.gdata.de/login

// If you got a client id and client secret from us, you can use the ClientCredentialsGrantAuthenticator like this
else{
Expand Down
8 changes: 4 additions & 4 deletions python/examples/VaasExample/authentication_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ async def main():
# If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this
if USE_RESOURCE_OWNER_PASSWORD_GRANT_AUTHENTICATOR:
authenticator = ResourceOwnerPasswordGrantAuthenticator(
os.getenv("VAAS_CLIENT_ID"),
"vaas-customer",
os.getenv("VAAS_USER_NAME"),
os.getenv("VAAS_PASSWORD"),
token_endpoint=token_url
)
# If you got a client id with a link you may use self registration and create a new username and password for the
# ResourceOwnerPasswordAuthenticator by yourself like the example above.
# You may use self registration and create a new username and password for the
# ResourceOwnerPasswordAuthenticator by yourself like the example above on https://vaas.gdata.de/login

# If you got a client id and client secret from us, you can use the ClientCredentialsGrantAuthenticator like this
# Else if you got a client id and client secret from us, you can use the ClientCredentialsGrantAuthenticator like this
else:
authenticator = ClientCredentialsGrantAuthenticator(
os.getenv("CLIENT_ID"),
Expand Down

0 comments on commit 77c9858

Please sign in to comment.