Integration and Usage
Initialization
Include the SDK dependencies to the local Maven repository:
mvn install:install-file -DgroupId=com.github.ontio -DartifactId=ontlogin-sdk-java -Dversion=1.0.0 -Dpackaging=jar -Dfile=ontlogin-sdk-java-1.0.0.jarAdd dependencies in the pom.xml file:
<dependency>
<groupId>com.github.ontio</groupId>
<artifactId>ontlogin-sdk-java</artifactId>
<version>1.0.0</version>
</dependency>Add API Methods
Add the methods in the Controller:
requestChallenge: Returns the challenge from the serversubmitChallenge: Passes the signed challenge and VP (if requested by the server)
// Challenge request
@PostMapping("/challenge")
public Result generateChallenge(@RequestBody ClientHello clientHello) throws Exception {
String action = "generateChallenge";
ServerHello result = loginService.generateChallenge(action, clientHello);
return new Result(action, ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.descEN(), result);
}
// Challenge submission
@PostMapping("/validate")
public Result validateClientResponse(@RequestBody ClientResponse clientResponse) throws Exception {
String action = "validateClientResponse";
String token = loginService.validateClientResponse(action, clientResponse);
return new Result(action, ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.descEN(), token);
}
// Other business logic
@PostMapping("/check-jwt")
public Result checkJwt(@RequestBody JSONObject req) {
String action = "checkJwt";
String token = req.getString("token");
loginService.checkJwt(action, token);
return new Result(action, ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.descEN(), ErrorInfo.SUCCESS.descEN());
}Use loginService
loginServiceImport SDKUtil and Initialize ontlogin Sdk
SDKUtil and Initialize ontlogin SdkHandle VP
Use the following to extract VC from VP in form of JSON text.
Since the form of VC varies according to the server's request, only JSON is supported here. The server can parse the VC into the per-defined form.
Last updated