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 2265 - Send state in OVP response and request body as url query items #11

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct AuthorizationResponse{
}
}

static func shareVp(vpResponseMetadata: VPResponseMetadata, nonce: String, responseUri: String, presentationDefinitionId: String, networkManager: NetworkManaging) async throws -> String? {
static func shareVp(vpResponseMetadata: VPResponseMetadata, nonce: String, state: String, responseUri: String, presentationDefinitionId: String, networkManager: NetworkManaging) async throws -> String? {

try vpResponseMetadata.validate()

Expand All @@ -50,10 +50,10 @@ struct AuthorizationResponse{

let vpToken = VpToken.constructVpToken(signingVPToken: vpTokenForSigning!, proof: proof)

return try await constructHttpRequestBody(vpToken: vpToken, presentationSubmission: presentationSubmission, responseUri: responseUri, networkManager: networkManager)
return try await constructHttpRequestBody(vpToken: vpToken, presentationSubmission: presentationSubmission, responseUri: responseUri, state: state, networkManager: networkManager)
}

private static func constructHttpRequestBody(vpToken: VpToken, presentationSubmission: PresentationSubmission, responseUri: String, networkManager: NetworkManaging = NetworkManager.shared) async throws -> String? {
private static func constructHttpRequestBody(vpToken: VpToken, presentationSubmission: PresentationSubmission, responseUri: String, state: String, networkManager: NetworkManaging = NetworkManager.shared) async throws -> String? {

guard let encodedVPTokenData = try? encodeToJsonString(vpToken) else {
Logger.error("Vp token encoding failed.")
Expand All @@ -65,12 +65,15 @@ struct AuthorizationResponse{
throw AuthorizationResponseException.jsonEncodingException(fieldName: "presentationSubmission")
}

let requestBody = """
{
"vp_token": \(encodedVPTokenData),
"presentation_submission": \(encodedPresentationSubmissionData)
}
"""
var bodyComponents = [URLQueryItem]()
bodyComponents.append(URLQueryItem(name: "vp_token", value: encodedVPTokenData))
bodyComponents.append(URLQueryItem(name: "presentation_submission", value: encodedPresentationSubmissionData))
bodyComponents.append(URLQueryItem(name: "state", value: state))

var urlComponents = URLComponents()
urlComponents.queryItems = bodyComponents

let requestBody = urlComponents.percentEncodedQuery!

guard let url = URL(string: responseUri) else {
Logger.error("Invalid response uri.")
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenID4VP/OpenID4VP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class OpenID4VP {
public func shareVerifiablePresentation(vpResponseMetadata: VPResponseMetadata) async throws -> String? {

do {
return try await AuthorizationResponse.shareVp(vpResponseMetadata: vpResponseMetadata,nonce: authorizationRequest!.nonce, responseUri: authorizationRequest!.responseUri,presentationDefinitionId: (authorizationRequest?.presentationDefinition as! PresentationDefinition).id, networkManager: networkManager)
return try await AuthorizationResponse.shareVp(vpResponseMetadata: vpResponseMetadata,nonce: authorizationRequest!.nonce, state: authorizationRequest!.state, responseUri: authorizationRequest!.responseUri,presentationDefinitionId: (authorizationRequest?.presentationDefinition as! PresentationDefinition).id, networkManager: networkManager)
} catch(let exception) {
await sendErrorToVerifier(error: exception)
throw exception
Expand Down
Loading