-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathResponses.swift
More file actions
218 lines (188 loc) · 6.81 KB
/
Copy pathResponses.swift
File metadata and controls
218 lines (188 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//
// Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved.
// The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
//
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and limitations under the License.
//
import Foundation
import AuthFoundation
#if !COCOAPODS
import JSON
#endif
enum IDXIONObjectType: Sendable {
case Link
}
protocol IDXIONObject: Decodable {
var type: IDXIONObjectType { get }
}
protocol IDXIONRelatable {
var relatableIdentifier: String? { get }
}
struct IDXOAuth2Error: Sendable, Codable, Error, LocalizedError {
let errorSummary: String
let errorCode: String?
let errorUri: String?
let errorLink: String?
let errorId: String?
var errorDescription: String? {
errorSummary
}
}
struct IDXError: Sendable, Codable {
let error: String
let errorDescription: String?
let errorUri: String?
let interactionHandle: String
}
final class IonResponse: Sendable, Decodable, JSONDecodable, ReceivesIDXResponse {
let stateHandle: String?
let version: String
let expiresAt: Date?
let intent: String?
let remediation: IonCollection<IonForm>?
let messages: IonCollection<IonMessage>?
let authenticators: IonCollection<IonAuthenticator>?
let authenticatorEnrollments: IonCollection<IonAuthenticator>?
let currentAuthenticatorEnrollment: IonObject<IonAuthenticator>?
let currentAuthenticator: IonObject<IonAuthenticator>?
let recoveryAuthenticator: IonObject<IonAuthenticator>?
let webauthnAutofillUIChallenge: IonObject<IonChallengeData>?
let user: IonObject<IonUser>?
let app: IonObject<IonApp>?
let successWithInteractionCode: IonForm?
let cancel: IonForm?
static var jsonDecoder: JSONDecoder {
idxResponseDecoder
}
}
struct IonObject<T: Sendable & Decodable>: Sendable, Decodable, ReceivesIDXResponse {
let type: String?
let value: T
}
struct IonCollection<T: Sendable & Decodable>: Sendable, Decodable, ReceivesIDXResponse {
let type: String?
let value: [T]
}
struct IonUser: Sendable, Decodable, ReceivesIDXResponse {
let id: String?
let profile: [String: String?]?
let identifier: String?
}
struct IonApp: Sendable, Decodable, ReceivesIDXResponse {
let id: String
let label: String
let name: String
}
struct IonChallengeData: Sendable, Decodable, ReceivesIDXResponse {
let challengeData: JSON
}
struct IonAuthenticator: Sendable, Decodable, IDXIONRelatable, ReceivesIDXResponse {
let displayName: String?
let id: String?
let type: Authenticator.Kind
let key: String?
let methods: [[String: String]]?
let settings: JSON?
let contextualData: [String: JSON]?
let profile: [String: String]?
let send: IonForm?
let resend: IonForm?
let poll: IonForm?
let recover: IonForm?
var relatableIdentifier: String? { id }
var jsonPath: String?
}
struct IonForm: Sendable, Decodable, ReceivesIDXResponse {
let rel: [String]?
let name: String
let method: APIRequestMethod
let href: URL
let value: [IonFormValue]?
let accepts: APIContentType?
let relatesTo: [String]?
let refresh: Double?
let type: String?
let idp: [String: String]?
}
struct IonCompositeForm: Sendable, Decodable, ReceivesIDXResponse {
let form: IonCompositeFormValue
}
struct IonCompositeFormValue: Sendable, Decodable, ReceivesIDXResponse {
let value: [IonFormValue]
}
struct IonFormValue: Sendable, Decodable, ReceivesIDXResponse {
enum Value: Sendable {
case json(JSON)
case compositeForm(IonCompositeForm)
}
let id: String?
let name: String?
let label: String?
let type: String?
let value: JSON
let valueAsCompositeForm: IonCompositeForm?
let required: Bool?
let secret: Bool?
let visible: Bool?
let mutable: Bool?
let form: IonCompositeFormValue?
let options: [IonFormValue]?
let relatesTo: String?
let messages: IonCollection<IonMessage>?
private enum CodingKeys: String, CodingKey {
case id, name, required, label, type, value, secret, visible, mutable, options, form, relatesTo, messages
}
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(String.self, forKey: .id)
name = try container.decodeIfPresent(String.self, forKey: .name)
label = try container.decodeIfPresent(String.self, forKey: .label)
type = try container.decodeIfPresent(String.self, forKey: .type)
required = try container.decodeIfPresent(Bool.self, forKey: .required)
secret = try container.decodeIfPresent(Bool.self, forKey: .secret)
visible = try container.decodeIfPresent(Bool.self, forKey: .visible)
mutable = try container.decodeIfPresent(Bool.self, forKey: .mutable)
relatesTo = try container.decodeIfPresent(String.self, forKey: .relatesTo)
options = try container.decodeIfPresent([IonFormValue].self, forKey: .options)
messages = try container.decodeIfPresent(IonCollection<IonMessage>.self, forKey: .messages)
let formObj = try? container.decodeIfPresent(IonCompositeFormValue.self, forKey: .form)
valueAsCompositeForm = try? container.decodeIfPresent(IonCompositeForm.self, forKey: .value)
value = try container.decodeIfPresent(JSON.self, forKey: .value) ?? .null
if formObj == nil && valueAsCompositeForm != nil {
form = valueAsCompositeForm?.form
} else {
form = formObj
}
}
}
struct IonMessage: Sendable, Codable, ReceivesIDXResponse {
let type: String
let i18n: IonLocalization?
let message: String
struct IonLocalization: Codable {
let key: String
}
private enum CodingKeys: String, CodingKey {
case type = "class", i18n, message
}
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
type = try container.decode(String.self, forKey: .type)
i18n = try container.decodeIfPresent(IonLocalization.self, forKey: .i18n)
message = try container.decode(String.self, forKey: .message)
}
}
/// Internal OIE API v1.0.0 token response.
final class IonToken: NSObject, Decodable, ReceivesIDXResponse {
let tokenType: String
let expiresIn: Int
let accessToken: String
let scope: String
let refreshToken: String?
let idToken: String?
}