Skip to content

Commit

Permalink
[Injimob 1629] refactor OpenId4vp setter methods into non static meth…
Browse files Browse the repository at this point in the history
…ods (#2)

* [INJIMOB-1629] add a Kotlin module to implement the OpenID4VP Android native artifact

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add logic to decode, parse authorization request and authenticate verifier using clientID received in request

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] override deserialize method of kotlin serialization library to add null check validations for mandatory fields and add validate method in all classes to check for other validations

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] reorganize the folder structure to group related code

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add validation in field class to check if the path variable is starting with regex mentioned in the spec

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] use apache codec binary base64 decoder to decode received authorization request

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] refactor getAuthenticationResponse method to support scope request param and add necessary error scenarios

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add method to construct and return vp token to wallet to get the proof section and signature value of it

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add method to receive vp token signature value and send http post request to the verifier

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add serializable annotation to proof, vpToken related classes to add alias name for the context class variable in generated json string

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] rename field class to fields to match the spec and set default value of optional fields to null in all classes to fix deserialization issue

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add testcases for Authorization requst success and error scenarios

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] pass the shareVp methods arguments as vpResponseMetadata instance and handle vp sharing network call and it's exceptions

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] mark presentation submission class as serializable and add serial names for the class variables

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add uuid generator util function to generate unique uuid value for vp_token and presentation_submission

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] return response body as string in network manager if response status is successful and throw errors for different scenarios

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] make changes in the vpResponseMetadata class to throw error if any input parameter is empty

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add testing dependencies and write different test cases for Authorization Request class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] write different test cases for Authorization Response class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] write different test cases for decoder class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] make changes in the vpResponseMetadata class to throw error if any input parameter value is null

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] remove format field from all the files to support draft 13 changes

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] rename shared folder to common folder

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] mark limit disclosure class as serializable

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add logger class and log the error messages wherever we are throwing errors in the code

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] format all the files

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add jacoco plugin and task for generating code coverage report

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add test for checking invalid path param and refactor error message variable names in test cases

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] extract serializer outside in all the auth request classes and override the serialize method and create function to handle the exceptions

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] remove index from the error messages to keep the error messages consistent in deserialize and validate methods

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] write test cases for input descriptor and presentation definition classes

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] change invalid input exception message

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] ignore serialize overrided methods of auth request classes

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] write test cases for constraints, fields & filter classes

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] write test cases for logger class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add configuration for generating artifact and publishing it into maven

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] convert Authorization response class methods into static methods using companion and remove auth response variable in openId4VP class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add workflows for push trigger and for publishing the artifact into maven

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] return exception from logger class handle exception method rather than throwing it

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] remove inji reference from authorization request test class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] throw custom errors for any issues occured during serialization and query params extraction

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add readme file in kotlin openId4VP folder explaining the functionalities and APIs

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] refactor invalid input exception message

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] remove sharingTimeoutInMilliseconds argument from vpResponseMetadata class

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add code to send error to the verifier via post request if response uri is valid

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] remove example folder

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] make http call synchronous when sending error message to the verifier and refactor few error messages

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] remove redundant exception suffix for some of the exceptions in all files

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] update artifact version and readme

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] add license file

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] update gitignore file to ignore .idea folder and delete them

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] update publish artifact file with missing pom properties

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] avoid passing openId4VP class reference to the methods and use setter methods and pass actual params directly

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] convert responseUri and presentationDefinitionId setter methods into non-static methods and pass them as arguments to another classes

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

* [INJIMOB-1629] rename android publsih file to android maven publish

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>

---------

Signed-off-by: PuBHARGAVI <46226958+PuBHARGAVI@users.noreply.github.com>
  • Loading branch information
PuBHARGAVI authored Sep 3, 2024
1 parent 805415e commit fb2ba89
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
File renamed without changes.
27 changes: 12 additions & 15 deletions kotlin/openId4VP/src/main/java/io/mosip/openID4VP/OpenId4VP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,30 @@ import io.mosip.openID4VP.dto.Verifier
import io.mosip.openID4VP.networkManager.NetworkManagerClient.Companion.sendHttpPostRequest
import okhttp3.ResponseBody.Companion.toResponseBody

private val logTag = Logger.getLogTag(AuthorizationResponse::class.simpleName!!)
class OpenId4VP(private val traceabilityId: String) {
lateinit var authorizationRequest: AuthorizationRequest
private lateinit var logTag: String
private lateinit var presentationDefinitionId: String
private var responseUri: String? = null

companion object {
private lateinit var presentationDefinitionId: String
private var responseUri: String? = null

fun setResponseUri(responseUri: String) {
this.responseUri = responseUri
}
fun setResponseUri(responseUri: String) {
this.responseUri = responseUri
}

fun setPresentationDefinitionId(id: String) {
this.presentationDefinitionId = id
}
fun setPresentationDefinitionId(id: String) {
this.presentationDefinitionId = id
}

fun authenticateVerifier(
encodedAuthorizationRequest: String, trustedVerifiers: List<Verifier>
): Map<String, String> {
try {
Logger.setTraceability(traceabilityId)
logTag = Logger.getLogTag(AuthorizationRequest::class.simpleName!!)
authorizationRequest =
AuthorizationRequest.getAuthorizationRequest(encodedAuthorizationRequest)
authorizationRequest = AuthorizationRequest.getAuthorizationRequest(
encodedAuthorizationRequest, ::setResponseUri
)
return AuthenticationResponse.getAuthenticationResponse(
authorizationRequest, trustedVerifiers
authorizationRequest, trustedVerifiers, ::setPresentationDefinitionId
)
} catch (exception: Exception) {
sendErrorToVerifier(exception)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.mosip.openID4VP.authenticationResponse

import io.mosip.openID4VP.OpenId4VP
import io.mosip.openID4VP.authorizationRequest.AuthorizationRequest
import io.mosip.openID4VP.authorizationRequest.exception.AuthorizationRequestExceptions
import io.mosip.openID4VP.authorizationRequest.presentationDefinition.PresentationDefinition
Expand All @@ -12,6 +11,7 @@ class AuthenticationResponse {
fun getAuthenticationResponse(
authorizationRequest: AuthorizationRequest,
trustedVerifiers: List<Verifier>,
setPresentationDefinitionId: (String) -> Unit
): Map<String, String> {
val response = mutableMapOf<String, String>()
validateVerifierClientID(
Expand All @@ -25,7 +25,7 @@ class AuthenticationResponse {
presentationDefinitionJson?.let {
val presentationDefinition: PresentationDefinition =
validatePresentationDefinition(presentationDefinitionJson)
OpenId4VP.setPresentationDefinitionId(presentationDefinition.id)
setPresentationDefinitionId(presentationDefinition.id)
response.put("presentation_definition", presentationDefinitionJson)
}
val scope = authorizationRequest.scope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package io.mosip.openID4VP.authorizationRequest

import io.mosip.openID4VP.OpenId4VP
import io.mosip.openID4VP.authorizationRequest.exception.AuthorizationRequestExceptions
import io.mosip.openID4VP.common.Decoder
import io.mosip.openID4VP.common.Logger
import java.net.URI
import java.net.URLDecoder
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import io.mosip.openID4VP.OpenId4VP.Companion

private val logTag = Logger.getLogTag(AuthorizationRequest::class.simpleName!!)

Expand All @@ -23,17 +21,21 @@ class AuthorizationRequest(
val state: String
) {
companion object {
fun getAuthorizationRequest(encodedAuthorizationRequest: String): AuthorizationRequest {
fun getAuthorizationRequest(
encodedAuthorizationRequest: String, setResponseUri: (String) -> Unit
): AuthorizationRequest {
try {
val decodedAuthorizationRequest =
Decoder.decodeBase64ToString(encodedAuthorizationRequest)
return parseAuthorizationRequest(decodedAuthorizationRequest)
return parseAuthorizationRequest(decodedAuthorizationRequest, setResponseUri)
} catch (e: Exception) {
throw e
}
}

private fun parseAuthorizationRequest(decodedAuthorizationRequest: String): AuthorizationRequest {
private fun parseAuthorizationRequest(
decodedAuthorizationRequest: String, setResponseUri: (String) -> Unit
): AuthorizationRequest {
try {
val queryStart = decodedAuthorizationRequest.indexOf('?') + 1
val queryString = decodedAuthorizationRequest.substring(queryStart)
Expand All @@ -44,7 +46,7 @@ class AuthorizationRequest(
?: throw AuthorizationRequestExceptions.InvalidQueryParams("Query parameters are missing in the Authorization request")

val params = extractQueryParams(query)
validateQueryParams(params)
validateQueryParams(params, setResponseUri)
return createAuthorizationRequest(params)
} catch (exception: Exception) {
Logger.error(logTag, exception)
Expand All @@ -64,7 +66,9 @@ class AuthorizationRequest(
}
}

private fun validateQueryParams(params: Map<String, String>) {
private fun validateQueryParams(
params: Map<String, String>, setResponseUri: (String) -> Unit
) {
val requiredRequestParams = mutableListOf(
"response_uri",
"client_id",
Expand Down Expand Up @@ -97,7 +101,7 @@ class AuthorizationRequest(
requiredRequestParams.forEach { param ->
val value = params[param] ?: throw AuthorizationRequestExceptions.MissingInput(param)
if (param == "response_uri") {
OpenId4VP.setResponseUri(value)
setResponseUri(value)
}
require(value.isNotEmpty()) {
throw AuthorizationRequestExceptions.InvalidInput(param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.mosip.openID4VP.common.UUIDGenerator
import io.mosip.openID4VP.dto.VPResponseMetadata
import io.mosip.openID4VP.dto.Verifier
import io.mosip.openID4VP.networkManager.exception.NetworkManagerClientExceptions
import okhttp3.HttpUrl
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
Expand Down Expand Up @@ -72,7 +71,7 @@ class AuthorizationResponseTest {
)
mockWebServer = MockWebServer()
mockWebServer.start(8080)
OpenId4VP.setPresentationDefinitionId("6498781c-f291-4969-9cd5-2c273858f38f")
openId4VP.setPresentationDefinitionId("6498781c-f291-4969-9cd5-2c273858f38f")
openId4VP.authorizationRequest = AuthorizationRequest(
clientId = "https://injiverify.dev2.mosip.net",
responseType = "vp_token",
Expand Down

0 comments on commit fb2ba89

Please sign in to comment.