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

[Injimob 1629] refactor OpenId4vp setter methods into non static methods #2

Merged
merged 56 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e4a9777
[INJIMOB-1629] add a Kotlin module to implement the OpenID4VP Android…
PuBHARGAVI Jul 16, 2024
927045a
[INJIMOB-1629] add logic to decode, parse authorization request and a…
PuBHARGAVI Jul 17, 2024
8909cba
[INJIMOB-1629] override deserialize method of kotlin serialization li…
PuBHARGAVI Jul 25, 2024
91ef92d
[INJIMOB-1629] reorganize the folder structure to group related code
PuBHARGAVI Jul 26, 2024
8aaf4cd
[INJIMOB-1629] add validation in field class to check if the path var…
PuBHARGAVI Jul 26, 2024
4a51f13
[INJIMOB-1629] use apache codec binary base64 decoder to decode recei…
PuBHARGAVI Jul 31, 2024
985ad62
[INJIMOB-1629] refactor getAuthenticationResponse method to support s…
PuBHARGAVI Jul 31, 2024
4eb8fa9
[INJIMOB-1629] add method to construct and return vp token to wallet …
PuBHARGAVI Aug 1, 2024
5bd909e
[INJIMOB-1629] add method to receive vp token signature value and sen…
PuBHARGAVI Aug 1, 2024
c180713
[INJIMOB-1629] add serializable annotation to proof, vpToken related …
PuBHARGAVI Aug 1, 2024
aeecbe6
[INJIMOB-1629] rename field class to fields to match the spec and set…
PuBHARGAVI Aug 2, 2024
1b79426
[INJIMOB-1629] add testcases for Authorization requst success and err…
PuBHARGAVI Aug 2, 2024
722eb75
[INJIMOB-1629] pass the shareVp methods arguments as vpResponseMetada…
PuBHARGAVI Aug 5, 2024
77df40c
[INJIMOB-1629] mark presentation submission class as serializable and…
PuBHARGAVI Aug 5, 2024
c43c0b9
[INJIMOB-1629] add uuid generator util function to generate unique uu…
PuBHARGAVI Aug 5, 2024
991d1dd
[INJIMOB-1629] return response body as string in network manager if r…
PuBHARGAVI Aug 6, 2024
e72a128
[INJIMOB-1629] make changes in the vpResponseMetadata class to throw …
PuBHARGAVI Aug 6, 2024
c0a8bf3
[INJIMOB-1629] add testing dependencies and write different test case…
PuBHARGAVI Aug 6, 2024
c94fbeb
[INJIMOB-1629] write different test cases for Authorization Response …
PuBHARGAVI Aug 6, 2024
3904f7d
[INJIMOB-1629] write different test cases for decoder class
PuBHARGAVI Aug 6, 2024
f142213
[INJIMOB-1629] make changes in the vpResponseMetadata class to throw …
PuBHARGAVI Aug 6, 2024
ebfe8d3
[INJIMOB-1629] remove format field from all the files to support draf…
PuBHARGAVI Aug 7, 2024
3270541
[INJIMOB-1629] rename shared folder to common folder
PuBHARGAVI Aug 7, 2024
bfc2c5b
[INJIMOB-1629] mark limit disclosure class as serializable
PuBHARGAVI Aug 7, 2024
38c143a
[INJIMOB-1629] add logger class and log the error messages wherever w…
PuBHARGAVI Aug 7, 2024
6a221d5
[INJIMOB-1629] format all the files
PuBHARGAVI Aug 7, 2024
a1c619f
[INJIMOB-1629] add jacoco plugin and task for generating code coverag…
PuBHARGAVI Aug 7, 2024
c384888
[INJIMOB-1629] add test for checking invalid path param and refactor …
PuBHARGAVI Aug 7, 2024
0e08314
[INJIMOB-1629] extract serializer outside in all the auth request cla…
PuBHARGAVI Aug 11, 2024
27c7d6d
[INJIMOB-1629] remove index from the error messages to keep the error…
PuBHARGAVI Aug 11, 2024
53d3be1
[INJIMOB-1629] write test cases for input descriptor and presentation…
PuBHARGAVI Aug 11, 2024
86346ef
[INJIMOB-1629] change invalid input exception message
PuBHARGAVI Aug 11, 2024
a3edfb8
[INJIMOB-1629] ignore serialize overrided methods of auth request cla…
PuBHARGAVI Aug 11, 2024
673c527
[INJIMOB-1629] write test cases for constraints, fields & filter classes
PuBHARGAVI Aug 11, 2024
c01c019
[INJIMOB-1629] write test cases for logger class
PuBHARGAVI Aug 11, 2024
1d1584b
[INJIMOB-1629] add configuration for generating artifact and publishi…
PuBHARGAVI Aug 11, 2024
885015a
[INJIMOB-1629] convert Authorization response class methods into stat…
PuBHARGAVI Aug 12, 2024
ab50dfa
[INJIMOB-1629] add workflows for push trigger and for publishing the …
PuBHARGAVI Aug 12, 2024
8e926f4
[INJIMOB-1629] return exception from logger class handle exception me…
PuBHARGAVI Aug 12, 2024
ddfc998
[INJIMOB-1629] remove inji reference from authorization request test …
PuBHARGAVI Aug 12, 2024
108bd9b
[INJIMOB-1629] throw custom errors for any issues occured during seri…
PuBHARGAVI Aug 12, 2024
def991b
[INJIMOB-1629] add readme file in kotlin openId4VP folder explaining …
PuBHARGAVI Aug 12, 2024
482ddae
[INJIMOB-1629] refactor invalid input exception message
PuBHARGAVI Aug 13, 2024
34e29e8
[INJIMOB-1629] remove sharingTimeoutInMilliseconds argument from vpRe…
PuBHARGAVI Aug 13, 2024
f549506
[INJIMOB-1629] add code to send error to the verifier via post reques…
PuBHARGAVI Aug 21, 2024
74d3b73
[INJIMOB-1629] remove example folder
PuBHARGAVI Aug 21, 2024
adad6b4
[INJIMOB-1629] make http call synchronous when sending error message …
PuBHARGAVI Aug 26, 2024
319fd04
[INJIMOB-1629] remove redundant exception suffix for some of the exce…
PuBHARGAVI Aug 27, 2024
88d36a7
[INJIMOB-1629] update artifact version and readme
PuBHARGAVI Aug 27, 2024
bedde01
[INJIMOB-1629] add license file
PuBHARGAVI Aug 28, 2024
17d0eaf
[INJIMOB-1629] update gitignore file to ignore .idea folder and delet…
PuBHARGAVI Aug 28, 2024
d9ff2be
[INJIMOB-1629] update publish artifact file with missing pom properties
PuBHARGAVI Aug 28, 2024
bc7600d
[INJIMOB-1629] avoid passing openId4VP class reference to the methods…
PuBHARGAVI Aug 28, 2024
9a863b2
[INJIMOB-1629] convert responseUri and presentationDefinitionId sette…
PuBHARGAVI Sep 3, 2024
bd77d6f
[INJIMOB-1629] resolve conflicts
PuBHARGAVI Sep 3, 2024
85ef1cf
[INJIMOB-1629] rename android publsih file to android maven publish
PuBHARGAVI Sep 3, 2024
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
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
Loading