diff --git a/Sources/Entities/AuthorisationRequestObject.swift b/Sources/Entities/AuthorisationRequestObject.swift index 2cf6c40..fd06f83 100644 --- a/Sources/Entities/AuthorisationRequestObject.swift +++ b/Sources/Entities/AuthorisationRequestObject.swift @@ -27,6 +27,7 @@ public struct AuthorisationRequestObject: Codable { public let presentationDefinitionUri: String? public let request: String? public let requestUri: String? + public let requestUriMethod: String? public let clientMetaData: String? public let clientId: String? public let clientMetadataUri: String? @@ -45,7 +46,7 @@ public struct AuthorisationRequestObject: Codable { case presentationDefinition = "presentation_definition" case presentationDefinitionUri = "presentation_definition_uri" case clientId = "client_id" - case clientMetaData = "client_meta_data" + case clientMetaData = "client_metadata" case clientMetadataUri = "client_metadata_uri" case clientIdScheme = "client_id_scheme" case nonce @@ -55,6 +56,7 @@ public struct AuthorisationRequestObject: Codable { case idTokenType = "id_token_type" case request case requestUri = "request_uri" + case requestUriMethod = "request_uri_method" case supportedAlgorithm = "supported_algorithm" } @@ -66,6 +68,7 @@ public struct AuthorisationRequestObject: Codable { presentationDefinitionUri: String? = nil, request: String? = nil, requestUri: String? = nil, + requestUriMethod: String? = nil, clientMetaData: String? = nil, clientId: String? = nil, clientMetadataUri: String? = nil, @@ -84,6 +87,7 @@ public struct AuthorisationRequestObject: Codable { self.presentationDefinitionUri = presentationDefinitionUri self.request = request self.requestUri = requestUri + self.requestUriMethod = requestUriMethod self.clientMetaData = clientMetaData self.clientId = clientId self.clientMetadataUri = clientMetadataUri @@ -119,7 +123,8 @@ public struct AuthorisationRequestObject: Codable { request = try? container.decode(String.self, forKey: .request) requestUri = try? container.decode(String.self, forKey: .requestUri) - + requestUriMethod = try? container.decode(String.self, forKey: .requestUriMethod) + supportedAlgorithm = try? container.decode(String.self, forKey: .supportedAlgorithm) } @@ -147,7 +152,8 @@ public struct AuthorisationRequestObject: Codable { try? container.encode(request, forKey: .request) try? container.encode(requestUri, forKey: .requestUri) - + try? container.encode(requestUriMethod, forKey: .requestUriMethod) + try? container.encode(supportedAlgorithm, forKey: .supportedAlgorithm) } } @@ -177,7 +183,8 @@ public extension AuthorisationRequestObject { request = parameters?[CodingKeys.request.rawValue] as? String requestUri = parameters?[CodingKeys.requestUri.rawValue] as? String - + requestUriMethod = parameters?[CodingKeys.requestUriMethod.rawValue] as? String + supportedAlgorithm = parameters?[CodingKeys.supportedAlgorithm.rawValue] as? String } } diff --git a/Sources/PresentationDefinition/PresentationDefinitionSource.swift b/Sources/PresentationDefinition/PresentationDefinitionSource.swift index 7cab246..48c83d7 100644 --- a/Sources/PresentationDefinition/PresentationDefinitionSource.swift +++ b/Sources/PresentationDefinition/PresentationDefinitionSource.swift @@ -33,6 +33,19 @@ public extension PresentationDefinitionSource { } else if let uri = authorizationRequestObject[Constants.PRESENTATION_DEFINITION_URI].string, let uri = URL(string: uri) { self = .fetchByReference(url: uri) + } else if let presentationDefinitionString = authorizationRequestObject[Constants.PRESENTATION_DEFINITION].string { + + guard let jsonData = presentationDefinitionString.data(using: .utf8) else { + throw PresentationError.invalidPresentationDefinition + } + + if let container = try? JSONDecoder().decode(PresentationDefinitionContainer.self, from: jsonData) { + self = .passByValue(presentationDefinition: container.definition) + } else { + let definition = try JSONDecoder().decode(PresentationDefinition.self, from: jsonData) + self = .passByValue(presentationDefinition: definition) + } + } else if let scope = authorizationRequestObject[Constants.SCOPE].string, !scope.components(separatedBy: " ").isEmpty { self = .implied(scope: scope.components(separatedBy: " ")) diff --git a/Tests/EntitiesTests.swift b/Tests/EntitiesTests.swift index ae61c77..99e4415 100644 --- a/Tests/EntitiesTests.swift +++ b/Tests/EntitiesTests.swift @@ -201,7 +201,7 @@ class AuthorizationRequestUnprocessedDataTests: XCTestCase { "presentation_definition_uri": "https://example.com/definition", "request": "request", "request_uri": "https://example.com/request", - "client_meta_data": "clientMetaData", + "client_metadata": "clientMetaData", "client_id": "clientId", "client_metadata_uri": "https://example.com/metadata", "client_id_scheme": "clientScheme", @@ -237,7 +237,7 @@ class AuthorizationRequestUnprocessedDataTests: XCTestCase { } func testInitFromURL() { - let url = URL(string: "https://example.com?response_type=code&response_uri=https%3A%2F%2Fexample.com%2Fresponse&redirect_uri=https%3A%2F%2Fexample.com%2Fredirect&presentation_definition=presentationDefinition&presentation_definition_uri=https%3A%2F%2Fexample.com%2Fdefinition&request=request&request_uri=https%3A%2F%2Fexample.com%2Frequest&client_meta_data=clientMetaData&client_id=clientId&client_metadata_uri=https%3A%2F%2Fexample.com%2Fmetadata&client_id_scheme=clientScheme&nonce=nonce&scope=scope&response_mode=responseMode&state=state&id_token_type=idTokenType")! + let url = URL(string: "https://example.com?response_type=code&response_uri=https%3A%2F%2Fexample.com%2Fresponse&redirect_uri=https%3A%2F%2Fexample.com%2Fredirect&presentation_definition=presentationDefinition&presentation_definition_uri=https%3A%2F%2Fexample.com%2Fdefinition&request=request&request_uri=https%3A%2F%2Fexample.com%2Frequest&client_metadata=clientMetaData&client_id=clientId&client_metadata_uri=https%3A%2F%2Fexample.com%2Fmetadata&client_id_scheme=clientScheme&nonce=nonce&scope=scope&response_mode=responseMode&state=state&id_token_type=idTokenType")! let data = AuthorisationRequestObject(from: url) diff --git a/Tests/TestsConstants.swift b/Tests/TestsConstants.swift index ae7dc58..7a18a7d 100644 --- a/Tests/TestsConstants.swift +++ b/Tests/TestsConstants.swift @@ -18,8 +18,6 @@ import Foundation struct TestsConstants { - // MARK: - Claims - static let testClaimsBankAndPassport = [ Claim( id: "samplePassport",