diff --git a/.github/workflows/ci-java.yaml b/.github/workflows/ci-java.yaml index 91daac4e..1c4298ab 100644 --- a/.github/workflows/ci-java.yaml +++ b/.github/workflows/ci-java.yaml @@ -76,6 +76,13 @@ jobs: gradle-version: "8.1" build-root-directory: java/examples/VaasExample + - name: run authentication examples + uses: gradle/gradle-build-action@v2 + with: + arguments: authentication + gradle-version: "8.1" + build-root-directory: java/examples/VaasExample + - name: extract version if: startsWith(github.ref, 'refs/tags/java') run: | diff --git a/.github/workflows/ci-typescript.yaml b/.github/workflows/ci-typescript.yaml index 53f810c1..4317c408 100644 --- a/.github/workflows/ci-typescript.yaml +++ b/.github/workflows/ci-typescript.yaml @@ -76,11 +76,17 @@ jobs: - name: run examples scan file env: SCAN_PATH: "main.ts" - run: npx ts-node main.ts + run: pnpm start:filescan + working-directory: typescript/examples/VaasExample + + - name: run examples authentication + env: + SCAN_PATH: "authentication.ts" + run: pnpm start:authentication working-directory: typescript/examples/VaasExample - name: run examples scan url - run: npx ts-node url_scan.ts + run: pnpm start:urlscan working-directory: typescript/examples/VaasExample - name: extract version diff --git a/java/examples/VaasExample/build.gradle b/java/examples/VaasExample/build.gradle index 0853bf60..79f9ae99 100644 --- a/java/examples/VaasExample/build.gradle +++ b/java/examples/VaasExample/build.gradle @@ -23,3 +23,8 @@ task urlScan(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath mainClass = 'de.gdata.vaasexample.UrlScan' } + +task authentication(type: JavaExec) { + classpath = sourceSets.main.runtimeClasspath + mainClass = 'de.gdata.vaasexample.Authentication' +} diff --git a/java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Authentication.java b/java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Authentication.java index fa8e3d09..b9e76e9b 100644 --- a/java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Authentication.java +++ b/java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Authentication.java @@ -1,12 +1,8 @@ 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.*; import de.gdata.vaas.messages.VerdictRequestAttributes; import java.net.URI; -import java.nio.file.Path; public class Authentication { @@ -15,7 +11,6 @@ public static void main(String[] args) throws Exception { 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"); @@ -42,10 +37,9 @@ public static void main(String[] args) throws Exception { 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); + var verdict = vaas.forSha256(new Sha256("275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f"), verdictRequestAttributes); vaas.disconnect(); System.out.printf("File %s was detected as %s", verdict.getSha256(), verdict.getVerdict()); } diff --git a/typescript/examples/VaasExample/authentication.ts b/typescript/examples/VaasExample/authentication.ts index 3bbeca8d..2239e7a2 100644 --- a/typescript/examples/VaasExample/authentication.ts +++ b/typescript/examples/VaasExample/authentication.ts @@ -2,6 +2,7 @@ import { promises as fs } from "fs"; import { ClientCredentialsGrantAuthenticator, + ResourceOwnerPasswordGrantAuthenticator, Vaas, } from "gdata-vaas"; @@ -18,16 +19,30 @@ function getFromEnvironment(key: string) { async function main() { const CLIENT_ID = getFromEnvironment("CLIENT_ID"); const CLIENT_SECRET = getFromEnvironment("CLIENT_SECRET"); + const VAAS_USER_NAME = getFromEnvironment("VAAS_USER_NAME"); + const VAAS_PASSWORD = getFromEnvironment("VAAS_PASSWORD"); const SCAN_PATH = getFromEnvironment("SCAN_PATH"); const TOKEN_URL = getFromEnvironment("TOKEN_URL"); const VAAS_URL = getFromEnvironment("VAAS_URL"); - const authenticator = new ClientCredentialsGrantAuthenticator( - CLIENT_ID, - CLIENT_SECRET, + // If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this + const authenticator = new ResourceOwnerPasswordGrantAuthenticator( + "vaas-customer", + VAAS_USER_NAME, + VAAS_PASSWORD, TOKEN_URL ); + // 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 + // const authenticator = new ClientCredentialsGrantAuthenticator( + // CLIENT_ID, + // CLIENT_SECRET, + // TOKEN_URL + // ); + const vaas = new Vaas(); const token = await authenticator.getToken() await vaas.connect(token, VAAS_URL); diff --git a/typescript/examples/VaasExample/package.json b/typescript/examples/VaasExample/package.json index 009b40eb..c67933ff 100644 --- a/typescript/examples/VaasExample/package.json +++ b/typescript/examples/VaasExample/package.json @@ -5,13 +5,14 @@ "scripts": { "start:filescan": "npx ts-node main.ts", "start:urlscan": "npx ts-node url_scan.ts", + "start:authentication": "npx ts-node authentication.ts", "build": "tsc", "watch": "tsc -w" }, "author": "", "license": "ISC", "dependencies": { - "gdata-vaas": "5.3.0", + "gdata-vaas": "6.0.0", "ts-node": "^10.9.1", "@types/node": "20.4.8", "typescript": "5.1.6" @@ -20,4 +21,4 @@ "dotenv": "^16.0.0", "ts-node": "^10.9.1" } -} +} \ No newline at end of file diff --git a/typescript/examples/VaasExample/pnpm-lock.yaml b/typescript/examples/VaasExample/pnpm-lock.yaml index cae2743e..cd9f319d 100644 --- a/typescript/examples/VaasExample/pnpm-lock.yaml +++ b/typescript/examples/VaasExample/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: 20.4.8 version: 20.4.8 gdata-vaas: - specifier: 5.3.0 - version: 5.3.0 + specifier: 6.0.0 + version: 6.0.0 ts-node: specifier: ^10.9.1 version: 10.9.1(@types/node@20.4.8)(typescript@5.1.6) @@ -160,8 +160,8 @@ packages: mime-types: 2.1.35 dev: false - /gdata-vaas@5.3.0: - resolution: {integrity: sha512-kxE/2F0OBHlyf8Q91GAOhdklS8mToaJEoNA159b7Y962D+FDF0Q0WFltqI9E5OApnuaXT5ivb67JKPs65KsmRQ==} + /gdata-vaas@6.0.0: + resolution: {integrity: sha512-ATliRm+Xe2bxK3NIIcrZyiWAxXCiWbOQl5+o5yiFEZ+s79EGIbpfo8zpGvjPDfFrj2C16yu0fkSWHyXYwaAGAQ==} dependencies: '@types/uuid': 9.0.2 '@types/ws': 8.5.5