Skip to content

Commit

Permalink
Merge pull request #27 from niscy-eudiw/feature/update-auth--request-…
Browse files Browse the repository at this point in the history
…object

Update auth  request object
  • Loading branch information
dtsiflit authored Nov 4, 2024
2 parents bf9396b + 1ee4d5a commit 4e1ac57
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
15 changes: 11 additions & 4 deletions Sources/Entities/AuthorisationRequestObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand All @@ -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"
}

Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/PresentationDefinition/PresentationDefinitionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: " "))
Expand Down
4 changes: 2 additions & 2 deletions Tests/EntitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions Tests/TestsConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import Foundation

struct TestsConstants {

// MARK: - Claims

static let testClaimsBankAndPassport = [
Claim(
id: "samplePassport",
Expand Down

0 comments on commit 4e1ac57

Please sign in to comment.