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

feat: Java TDK auth & common packages #403

Merged
merged 24 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8c7358f
feat: boilerplate for java tdk
priyanka-affinidi Jan 7, 2025
4155b7a
feat: segregating commons and auth-provider
priyanka-affinidi Jan 9, 2025
cb391e4
feat: Adding AuthProvider
priyanka-affinidi Jan 10, 2025
1c68365
Merge branch 'main' into tdk-java
maratsh Jan 10, 2025
63d444a
Merge branch 'tdk-java' of github.com:affinidi/affinidi-tdk into tdk-…
priyanka-affinidi Jan 10, 2025
096eea7
feat: merge main
priyanka-affinidi Jan 10, 2025
800593e
feat: Added Jwt utility functions
priyanka-affinidi Jan 13, 2025
d73a912
Merge pull request #424 from affinidi/jwt-dependency
priyanka-affinidi Jan 13, 2025
1cfa195
feat: Implementation of AuthProvider and JwtUtil functions
priyanka-affinidi Jan 15, 2025
cd66c42
feat: added javadoc and exception handling
priyanka-affinidi Jan 15, 2025
039232c
Merge pull request #441 from affinidi/http_util
priyanka-affinidi Jan 15, 2025
4b65023
Merge branch 'main' into tdk-java
priyanka-affinidi Jan 20, 2025
40d9f78
docs: update readme
affrncsp Jan 20, 2025
fe26cb6
test: auth provider unit tests [FTL-18596] (#464)
aeffinidi Jan 20, 2025
60ac22b
docs: added vault-data-manager-client to the
affrncsp Jan 20, 2025
5b7a9b0
Merge pull request #483 from affinidi/docs/ftl-18981-readme
affrncsp Jan 20, 2025
87a1867
Manual Integration tests and fix for authprovider junits
priyanka-affinidi Jan 20, 2025
510aa76
Merge pull request #485 from affinidi/integration-test
priyanka-affinidi Jan 20, 2025
082ce50
fix: util => static
robert-affinidi Jan 21, 2025
108e493
fix: dotenv fixed
robert-affinidi Jan 21, 2025
3328445
feat: docs, linting, alignments
robert-affinidi Jan 21, 2025
109a59f
Merge pull request #492 from affinidi/fix/tdk-java-rob
robert-affinidi Jan 21, 2025
2df691c
Merge branch 'main' into tdk-java
maratsh Jan 22, 2025
656ed03
test: auth provider shouldRefreshToken unit tests (#493)
aeffinidi Jan 22, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Thumbs.db
.nx
.vscode

# Java
**/target
# Created by `dart pub`
.dart_tool/

Expand Down
7 changes: 7 additions & 0 deletions packages/java/auth.provider/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Optional values needed to generate auth token. These values can also be directly passsed to the AuthProvider build fuunction
PROJECT_ID=
KEY_ID=
TOKEN_ID=
PASSPHRASE=
PRIVATE_KEY=

90 changes: 90 additions & 0 deletions packages/java/auth.provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# auth.provider

AuthProvider package enables you to generate the required access token like Project Scoped Token to authenticate and access Affinidi Trust Network services.

For more information, please visit [https://github.com/affinidi/affinidi-tdk](https://github.com/affinidi/affinidi-tdk)

## Requirements

Building the package requires:

1. Java 1.8+
2. Maven (3.8.3+)

## Installation

To install the API client library to your local Maven repository, simply execute:

```shell
mvn clean install
```

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

```shell
mvn clean deploy
```

### Maven users

Add this dependency to your project's POM:

```xml
<dependency>
<groupId>com.affinidi.tdk</groupId>
<artifactId>auth.provider</artifactId>
<version>1.0.0</version>
</dependency>
```

### Others

At first generate the JAR by executing:

```shell
mvn clean package
```

## Usage

Sample usage to generate Project Scoped Token to call Affinidi TDK clients.

> You can store the required parameters like the Token details into an environment file.

```java

// Import classes:
import com.affinidi.tdk.authProvider.helper.JwtUtil;
import com.affinidi.tdk.authProvider.helper.AuthProvider;

public class AuthProviderConsumer {
public static void main(String arg[]) {
try{
// Create an authprovider from the values configured in the environment file
AuthProvider authProviderFromEnvFile = new AuthProvider.Configurations().buildWithEnv();
String projectToken = authProviderFromEnvFile.fetchProjectScopedToken();
System.out.println(projectToken);

boolean isExistingProjectScopeTokenValid = JwtUtil.validProjectTokenPresent(projectToken, authProviderFromEnvFile.apiGatewayUrl);
System.out.println(isExistingProjectScopeTokenValid);


// Alternatively you can create an auth provider by explicitly passing the configurations
AuthProvider authProviderWithPassedValues = new AuthProvider.Configurations()
.keyId("")
.projectId("")
.passphrase("")
.projectId("")
.tokenId("")
.build();
String projectToken = authProvider.fetchProjectScopedToken();
System.out.println(projectToken);


}catch(Exception e){
e.printStackTrace();
}
}
}

```
175 changes: 175 additions & 0 deletions packages/java/auth.provider/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>com.affinidi.tdk</groupId>
<artifactId>auth.provider</artifactId>
<version>1.0</version>
<name>auth.provider</name>
<url>https://github.com/affinidi/affinidi-tdk</url>
<licenses>
<license>
<name>Apache-2.0</name>
<url>https://github.com/affinidi/affinidi-tdk/blob/main/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<name>Affinidi</name>
<email>...</email>
<organization>Affinidi</organization>
<organizationUrl>https://affinidi.com</organizationUrl>
</developer>
</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<apache-http-version>5.4.1</apache-http-version>
<junit-version>5.11.0</junit-version>
<cdimascio-version>2.2.0</cdimascio-version>
<jersey-version>3.1.7</jersey-version>
<affinidi-common-version>1.0</affinidi-common-version>
<jsonwebtoken-version>0.12.6</jsonwebtoken-version>
<mockito-version>3.12.4</mockito-version>
<wiremock-version>3.10.0</wiremock-version>
<gson-version>2.10.1</gson-version>
<slf4j.version>2.0.16</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>${cdimascio-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.affinidi.tdk</groupId>
<artifactId>common</artifactId>
<version>${affinidi-common-version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>${jsonwebtoken-version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>${jsonwebtoken-version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>${jsonwebtoken-version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${apache-http-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>

</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to
parent pom) -->
<plugins>
<!-- clean lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Loading
Loading