Skip to content

Commit

Permalink
Fix: Migration to EWC RFC 001 - V2
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Oct 10, 2024
1 parent 4b8902b commit 8b4eaab
Show file tree
Hide file tree
Showing 14 changed files with 847 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
//
// Created by Mumthasir mohammed on 11/03/24.
//

import Foundation

// MARK: - AuthorisationServerWellKnownConfiguration
public struct AuthorisationServerWellKnownConfiguration: Codable {
public var redirectUris: [String]?
Expand All @@ -18,6 +16,8 @@ public struct AuthorisationServerWellKnownConfiguration: Codable {
public var requestAuthenticationMethodsSupported: RequestAuthenticationMethodsSupported?
public var vpFormatsSupported: VpFormatsSupported?
public var subjectSyntaxTypesSupported, subjectSyntaxTypesDiscriminations, subjectTrustFrameworksSupported, idTokenTypesSupported: [String]?
public var requirePushedAuthorizationRequests: Bool?
public var pushedAuthorizationRequestEndpoint: String?
public var error: EUDIError?

enum CodingKeys: String, CodingKey {
Expand All @@ -42,32 +42,28 @@ public struct AuthorisationServerWellKnownConfiguration: Codable {
case subjectSyntaxTypesDiscriminations = "subject_syntax_types_discriminations"
case subjectTrustFrameworksSupported = "subject_trust_frameworks_supported"
case idTokenTypesSupported = "id_token_types_supported"
case requirePushedAuthorizationRequests = "require_pushed_authorization_requests"
case pushedAuthorizationRequestEndpoint = "pushed_authorization_request_endpoint"
}
}

// MARK: - RequestAuthenticationMethodsSupported
public struct RequestAuthenticationMethodsSupported: Codable {
public var authorizationEndpoint: [String]?

enum CodingKeys: String, CodingKey {
case authorizationEndpoint = "authorization_endpoint"
}
}

// MARK: - VpFormatsSupported
public struct VpFormatsSupported: Codable {
public var jwtVp, jwtVc: JwtV?

enum CodingKeys: String, CodingKey {
case jwtVp = "jwt_vp"
case jwtVc = "jwt_vc"
}
}

// MARK: - JwtV
public struct JwtV: Codable {
var algValuesSupported: [String]?

enum CodingKeys: String, CodingKey {
case algValuesSupported = "alg_values_supported"
}
Expand Down
42 changes: 30 additions & 12 deletions Sources/eudiWalletOidcIos/Model/CredentialOffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
//
// Created by Mumthasir mohammed on 07/03/24.
//

import Foundation

// MARK: - CredentialOffer model
public struct CredentialOffer {
public var credentialIssuer: String?
public var credentials: [Credential]?
public var grants: Grants?
public var error: EUDIError?
public var version: String?

public init(from: CredentialOfferResponse) {
credentialIssuer = from.credentialIssuer

if let credentialList = from.credentials, credentialList.count > 0{

if let strCredentialList = credentialList as? [String]{
credentials = [Credential(fromTypes: strCredentialList)]
} else if let objCredentialList = credentialList as? [CredentialDataResponse]{
Expand All @@ -29,15 +27,35 @@ public struct CredentialOffer {
}
}
grants = from.grants == nil ? nil : Grants(from: from.grants!)
grants?.urnIETFParamsOauthGrantTypePreAuthorizedCode?.txCode = from.grants?.urnIETFParamsOauthGrantTypePreAuthorizedCode?.userPinRequired ?? false ? TransactionCode(length: 4, inputMode: "numeric", description: "") : nil
grants?.authorizationCode?.authorizationServer = nil
error = from.error == nil ? nil : EUDIError(from: from.error!)
version = "v1"
}

public init(from: CredentialOfferV2) {
credentialIssuer = from.credentialIssuer

if let credentialList = from.credentialConfigurationIds, credentialList.count > 0{
if let strCredentialList = credentialList as? [String]{
credentials = [Credential(fromTypes: strCredentialList)]
} else if let objCredentialList = credentialList as? [CredentialDataResponse]{
credentials = credentialList.map({
let obj = $0 as! CredentialDataResponse
return Credential(from: obj)
})
}
}
grants = from.grants == nil ? nil : Grants(from: from.grants!)
error = from.error == nil ? nil : EUDIError(from: from.error!)
version = "v2"
}

public init(fromError: EUDIError) {
error = fromError
}

}

// MARK: - Credential
public struct Credential {
public let format: String?
Expand All @@ -59,7 +77,6 @@ public struct Credential {
credentialDefinition = nil
}
}

// MARK: - CredentialDefinition
public struct CredentialDefinition {
public var context: [String]?
Expand All @@ -70,7 +87,6 @@ public struct CredentialDefinition {
types = from.types
}
}

// MARK: - TrustFramework
public struct TrustFramework {
public let name, type, uri: String?
Expand All @@ -81,33 +97,35 @@ public struct TrustFramework {
uri = from.uri
}
}

public struct Grants {
public let authorizationCode: AuthorizationCode?
public let urnIETFParamsOauthGrantTypePreAuthorizedCode: UrnIETFParamsOauthGrantTypePreAuthorizedCode?
public var authorizationCode: AuthorizationCode?
public var urnIETFParamsOauthGrantTypePreAuthorizedCode: UrnIETFParamsOauthGrantTypePreAuthorizedCode?

init(from: GrantsResponse) {
authorizationCode = from.authorizationCode == nil ? nil : AuthorizationCode(from: from.authorizationCode!)
urnIETFParamsOauthGrantTypePreAuthorizedCode = from.urnIETFParamsOauthGrantTypePreAuthorizedCode == nil ? nil : UrnIETFParamsOauthGrantTypePreAuthorizedCode(from: from.urnIETFParamsOauthGrantTypePreAuthorizedCode!)
}
}

// MARK: - AuthorizationCode
public struct AuthorizationCode {
public let issuerState: String?

public var authorizationServer: String?
init(from: AuthorizationCodeResponse) {
issuerState = from.issuerState
authorizationServer = from.authorizationServer
}
}

// MARK: - UrnIETFParamsOauthGrantTypePreAuthorizedCode
public struct UrnIETFParamsOauthGrantTypePreAuthorizedCode {
public let preAuthorizedCode: String?
public let userPinRequired: Bool?
public var txCode: TransactionCode?
public let authorizationServer: String?

init(from: UrnIETFParamsOauthGrantTypePreAuthorizedCodeResponse) {
preAuthorizedCode = from.preAuthorizedCode
userPinRequired = from.userPinRequired
txCode = from.txCode
authorizationServer = from.authorizationServer
}
}
7 changes: 7 additions & 0 deletions Sources/eudiWalletOidcIos/Model/CredentialOfferResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,26 @@ struct GrantsResponse: Codable {
// MARK: - AuthorizationCode
struct AuthorizationCodeResponse: Codable {
let issuerState: String?
let authorizationServer: String?

enum CodingKeys: String, CodingKey {
case issuerState = "issuer_state"
case authorizationServer = "authorization_server"
}
}

// MARK: - UrnIETFParamsOauthGrantTypePreAuthorizedCode
struct UrnIETFParamsOauthGrantTypePreAuthorizedCodeResponse: Codable {
let preAuthorizedCode: String?
let userPinRequired: Bool?
let txCode: TransactionCode?
let authorizationServer: String?

enum CodingKeys: String, CodingKey {
case preAuthorizedCode = "pre-authorized_code"
case userPinRequired = "user_pin_required"
case txCode = "tx_code"
case authorizationServer = "authorization_server"
}
}

61 changes: 61 additions & 0 deletions Sources/eudiWalletOidcIos/Model/CredentialOfferV2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// File.swift
//
//
// Created by oem on 10/10/24.
//

import Foundation

public struct CredentialOfferV2: Codable {
var credentialIssuer: String?
var credentialConfigurationIds: [AnyObject]?
var grants: GrantsResponse?
var error: ErrorResponse?

enum CodingKeys: String, CodingKey {
case credentialIssuer = "credential_issuer"
case credentialConfigurationIds = "credential_configuration_ids"
case grants, error
}


public func encode(to encoder: Encoder) throws {

}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.credentialIssuer = try container.decodeIfPresent(String.self, forKey: .credentialIssuer)
if let stringArray = try? container.decode([String].self, forKey: .credentialConfigurationIds) {
credentialConfigurationIds = stringArray as? [AnyObject]
} else if let credentialArray = try? container.decode([CredentialDataResponse].self, forKey: .credentialConfigurationIds) {
credentialConfigurationIds = credentialArray as? [AnyObject]
} else {
credentialConfigurationIds = nil
}
self.grants = try container.decodeIfPresent(GrantsResponse.self, forKey: .grants)
self.error = try container.decodeIfPresent(ErrorResponse.self, forKey: .error)
}

}

public struct TransactionCode: Codable {
public let length: Int?
public let inputMode: String?
public let description: String?

enum CodingKeys: String, CodingKey {
case length
case inputMode = "input_mode"
case description
}

init(length: Int? = 0, inputMode: String = "", description: String = "") {
self.length = length
self.inputMode = inputMode
self.description = description
}
}


36 changes: 29 additions & 7 deletions Sources/eudiWalletOidcIos/Model/CredentialResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,43 @@
//
// Created by Mumthasir mohammed on 11/03/24.
//

import Foundation

// MARK: - CredentialResponse
public struct CredentialResponse: Codable {
public struct CredentialResponse {
public var format, credential, acceptanceToken: String?
public var isDeferred, isPinRequired: Bool?
public var issuerConfig: IssuerWellKnownConfiguration?
public var authorizationConfig: AuthorisationServerWellKnownConfiguration?
public var credentialOffer: CredentialOffer?
public var error: EUDIError?

enum CodingKeys: String, CodingKey {
case acceptanceToken = "acceptance_token"
case format = "format"
case credential = "credential"

public init(from: CredentialResponseV1) {
format = from.format
credential = from.credential
acceptanceToken = from.acceptanceToken
isDeferred = from.isDeferred
isPinRequired = from.isPinRequired
issuerConfig = from.issuerConfig
authorizationConfig = from.authorizationConfig
credentialOffer = from.credentialOffer
error = from.error
}


public init(from: CredentialResponseV2) {
format = from.format
credential = from.credential
acceptanceToken = from.acceptanceToken
isDeferred = from.isDeferred
isPinRequired = from.isPinRequired
issuerConfig = from.issuerConfig
authorizationConfig = from.authorizationConfig
credentialOffer = from.credentialOffer
error = from.error
}

public init(fromError: EUDIError) {
error = fromError
}
}
23 changes: 23 additions & 0 deletions Sources/eudiWalletOidcIos/Model/CredentialResponseV1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// File.swift
//
//
// Created by oem on 10/10/24.
//

import Foundation

public struct CredentialResponseV1: Codable {
public var format, credential, acceptanceToken: String?
public var isDeferred, isPinRequired: Bool?
public var issuerConfig: IssuerWellKnownConfiguration?
public var authorizationConfig: AuthorisationServerWellKnownConfiguration?
public var credentialOffer: CredentialOffer?
public var error: EUDIError?

enum CodingKeys: String, CodingKey {
case acceptanceToken = "acceptance_token"
case format = "format"
case credential = "credential"
}
}
23 changes: 23 additions & 0 deletions Sources/eudiWalletOidcIos/Model/CredentialResponseV2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// File.swift
//
//
// Created by oem on 10/10/24.
//

import Foundation

public struct CredentialResponseV2: Codable {
public var format, credential, acceptanceToken: String?
public var isDeferred, isPinRequired: Bool?
public var issuerConfig: IssuerWellKnownConfiguration?
public var authorizationConfig: AuthorisationServerWellKnownConfiguration?
public var credentialOffer: CredentialOffer?
public var error: EUDIError?

enum CodingKeys: String, CodingKey {
case acceptanceToken = "transaction_id"
case format = "format"
case credential = "credential"
}
}
Loading

0 comments on commit 8b4eaab

Please sign in to comment.