-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathAccount.swift
1441 lines (1276 loc) · 43.5 KB
/
Account.swift
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import AsyncHTTPClient
import Foundation
import NIO
import JSONCodable
import AppwriteModels
/// The Account service allows you to authenticate and manage a user account.
open class Account: Service {
///
/// Get Account
///
/// Get the currently logged in user.
///
/// @throws Exception
/// @return array
///
open func get<T>(
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account"
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "GET",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Get Account
///
/// Get the currently logged in user.
///
/// @throws Exception
/// @return array
///
open func get(
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await get(
nestedType: [String: AnyCodable].self
)
}
///
/// Create Account
///
/// Use this endpoint to allow a new user to register a new account in your
/// project. After the user registration completes successfully, you can use
/// the [/account/verfication](/docs/client/account#accountCreateVerification)
/// route to start verifying the user email address. To allow the new user to
/// login to their new account, you need to create a new [account
/// session](/docs/client/account#accountCreateSession).
///
/// @param String userId
/// @param String email
/// @param String password
/// @param String name
/// @throws Exception
/// @return array
///
open func create<T>(
userId: String,
email: String,
password: String,
name: String? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account"
let apiParams: [String: Any?] = [
"userId": userId,
"email": email,
"password": password,
"name": name
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Create Account
///
/// Use this endpoint to allow a new user to register a new account in your
/// project. After the user registration completes successfully, you can use
/// the [/account/verfication](/docs/client/account#accountCreateVerification)
/// route to start verifying the user email address. To allow the new user to
/// login to their new account, you need to create a new [account
/// session](/docs/client/account#accountCreateSession).
///
/// @param String userId
/// @param String email
/// @param String password
/// @param String name
/// @throws Exception
/// @return array
///
open func create(
userId: String,
email: String,
password: String,
name: String? = nil
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await create(
userId: userId,
email: email,
password: password,
name: name,
nestedType: [String: AnyCodable].self
)
}
///
/// Update Email
///
/// Update currently logged in user account email address. After changing user
/// address, the user confirmation status will get reset. A new confirmation
/// email is not sent automatically however you can use the send confirmation
/// email endpoint again to send the confirmation email. For security measures,
/// user password is required to complete this request.
/// This endpoint can also be used to convert an anonymous account to a normal
/// one, by passing an email address and a new password.
///
///
/// @param String email
/// @param String password
/// @throws Exception
/// @return array
///
open func updateEmail<T>(
email: String,
password: String,
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account/email"
let apiParams: [String: Any?] = [
"email": email,
"password": password
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update Email
///
/// Update currently logged in user account email address. After changing user
/// address, the user confirmation status will get reset. A new confirmation
/// email is not sent automatically however you can use the send confirmation
/// email endpoint again to send the confirmation email. For security measures,
/// user password is required to complete this request.
/// This endpoint can also be used to convert an anonymous account to a normal
/// one, by passing an email address and a new password.
///
///
/// @param String email
/// @param String password
/// @throws Exception
/// @return array
///
open func updateEmail(
email: String,
password: String
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await updateEmail(
email: email,
password: password,
nestedType: [String: AnyCodable].self
)
}
///
/// List Identities
///
/// Get the list of identities for the currently logged in user.
///
/// @param String queries
/// @throws Exception
/// @return array
///
open func listIdentities(
queries: String? = nil
) async throws -> AppwriteModels.IdentityList {
let apiPath: String = "/account/identities"
let apiParams: [String: Any?] = [
"queries": queries
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.IdentityList = { response in
return AppwriteModels.IdentityList.from(map: response as! [String: Any])
}
return try await client.call(
method: "GET",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Delete Identity
///
/// Delete an identity by its unique ID.
///
/// @param String identityId
/// @throws Exception
/// @return array
///
open func deleteIdentity(
identityId: String
) async throws -> Any {
let apiPath: String = "/account/identities/{identityId}"
.replacingOccurrences(of: "{identityId}", with: identityId)
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
return try await client.call(
method: "DELETE",
path: apiPath,
headers: apiHeaders,
params: apiParams )
}
///
/// Create JWT
///
/// Use this endpoint to create a JSON Web Token. You can use the resulting JWT
/// to authenticate on behalf of the current user when working with the
/// Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
/// from its creation and will be invalid if the user will logout in that time
/// frame.
///
/// @throws Exception
/// @return array
///
open func createJWT(
) async throws -> AppwriteModels.Jwt {
let apiPath: String = "/account/jwt"
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Jwt = { response in
return AppwriteModels.Jwt.from(map: response as! [String: Any])
}
return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// List Logs
///
/// Get the list of latest security activity logs for the currently logged in
/// user. Each log returns user IP address, location and date and time of log.
///
/// @param [String] queries
/// @throws Exception
/// @return array
///
open func listLogs(
queries: [String]? = nil
) async throws -> AppwriteModels.LogList {
let apiPath: String = "/account/logs"
let apiParams: [String: Any?] = [
"queries": queries
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.LogList = { response in
return AppwriteModels.LogList.from(map: response as! [String: Any])
}
return try await client.call(
method: "GET",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update Name
///
/// Update currently logged in user account name.
///
/// @param String name
/// @throws Exception
/// @return array
///
open func updateName<T>(
name: String,
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account/name"
let apiParams: [String: Any?] = [
"name": name
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update Name
///
/// Update currently logged in user account name.
///
/// @param String name
/// @throws Exception
/// @return array
///
open func updateName(
name: String
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await updateName(
name: name,
nestedType: [String: AnyCodable].self
)
}
///
/// Update Password
///
/// Update currently logged in user password. For validation, user is required
/// to pass in the new password, and the old password. For users created with
/// OAuth, Team Invites and Magic URL, oldPassword is optional.
///
/// @param String password
/// @param String oldPassword
/// @throws Exception
/// @return array
///
open func updatePassword<T>(
password: String,
oldPassword: String? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account/password"
let apiParams: [String: Any?] = [
"password": password,
"oldPassword": oldPassword
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update Password
///
/// Update currently logged in user password. For validation, user is required
/// to pass in the new password, and the old password. For users created with
/// OAuth, Team Invites and Magic URL, oldPassword is optional.
///
/// @param String password
/// @param String oldPassword
/// @throws Exception
/// @return array
///
open func updatePassword(
password: String,
oldPassword: String? = nil
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await updatePassword(
password: password,
oldPassword: oldPassword,
nestedType: [String: AnyCodable].self
)
}
///
/// Update Phone
///
/// Update the currently logged in user's phone number. After updating the
/// phone number, the phone verification status will be reset. A confirmation
/// SMS is not sent automatically, however you can use the [POST
/// /account/verification/phone](/docs/client/account#accountCreatePhoneVerification)
/// endpoint to send a confirmation SMS.
///
/// @param String phone
/// @param String password
/// @throws Exception
/// @return array
///
open func updatePhone<T>(
phone: String,
password: String,
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account/phone"
let apiParams: [String: Any?] = [
"phone": phone,
"password": password
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update Phone
///
/// Update the currently logged in user's phone number. After updating the
/// phone number, the phone verification status will be reset. A confirmation
/// SMS is not sent automatically, however you can use the [POST
/// /account/verification/phone](/docs/client/account#accountCreatePhoneVerification)
/// endpoint to send a confirmation SMS.
///
/// @param String phone
/// @param String password
/// @throws Exception
/// @return array
///
open func updatePhone(
phone: String,
password: String
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await updatePhone(
phone: phone,
password: password,
nestedType: [String: AnyCodable].self
)
}
///
/// Get Account Preferences
///
/// Get the preferences as a key-value object for the currently logged in user.
///
/// @throws Exception
/// @return array
///
open func getPrefs<T>(
nestedType: T.Type
) async throws -> AppwriteModels.Preferences<T> {
let apiPath: String = "/account/prefs"
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Preferences<T> = { response in
return AppwriteModels.Preferences.from(map: response as! [String: Any])
}
return try await client.call(
method: "GET",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Get Account Preferences
///
/// Get the preferences as a key-value object for the currently logged in user.
///
/// @throws Exception
/// @return array
///
open func getPrefs(
) async throws -> AppwriteModels.Preferences<[String: AnyCodable]> {
return try await getPrefs(
nestedType: [String: AnyCodable].self
)
}
///
/// Update Preferences
///
/// Update currently logged in user account preferences. The object you pass is
/// stored as is, and replaces any previous value. The maximum allowed prefs
/// size is 64kB and throws error if exceeded.
///
/// @param Any prefs
/// @throws Exception
/// @return array
///
open func updatePrefs<T>(
prefs: Any,
nestedType: T.Type
) async throws -> AppwriteModels.User<T> {
let apiPath: String = "/account/prefs"
let apiParams: [String: Any?] = [
"prefs": prefs
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.User<T> = { response in
return AppwriteModels.User.from(map: response as! [String: Any])
}
return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Update Preferences
///
/// Update currently logged in user account preferences. The object you pass is
/// stored as is, and replaces any previous value. The maximum allowed prefs
/// size is 64kB and throws error if exceeded.
///
/// @param Any prefs
/// @throws Exception
/// @return array
///
open func updatePrefs(
prefs: Any
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
return try await updatePrefs(
prefs: prefs,
nestedType: [String: AnyCodable].self
)
}
///
/// Create Password Recovery
///
/// Sends the user an email with a temporary secret key for password reset.
/// When the user clicks the confirmation link he is redirected back to your
/// app password reset URL with the secret key and email address values
/// attached to the URL query string. Use the query string params to submit a
/// request to the [PUT
/// /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to
/// complete the process. The verification link sent to the user's email
/// address is valid for 1 hour.
///
/// @param String email
/// @param String url
/// @throws Exception
/// @return array
///
open func createRecovery(
email: String,
url: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/recovery"
let apiParams: [String: Any?] = [
"email": email,
"url": url
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Token = { response in
return AppwriteModels.Token.from(map: response as! [String: Any])
}
return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Create Password Recovery (confirmation)
///
/// Use this endpoint to complete the user account password reset. Both the
/// **userId** and **secret** arguments will be passed as query parameters to
/// the redirect URL you have provided when sending your request to the [POST
/// /account/recovery](/docs/client/account#accountCreateRecovery) endpoint.
///
/// Please note that in order to avoid a [Redirect
/// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
/// the only valid redirect URLs are the ones from domains you have set when
/// adding your platforms in the console interface.
///
/// @param String userId
/// @param String secret
/// @param String password
/// @param String passwordAgain
/// @throws Exception
/// @return array
///
open func updateRecovery(
userId: String,
secret: String,
password: String,
passwordAgain: String
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/recovery"
let apiParams: [String: Any?] = [
"userId": userId,
"secret": secret,
"password": password,
"passwordAgain": passwordAgain
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Token = { response in
return AppwriteModels.Token.from(map: response as! [String: Any])
}
return try await client.call(
method: "PUT",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// List Sessions
///
/// Get the list of active sessions across different devices for the currently
/// logged in user.
///
/// @throws Exception
/// @return array
///
open func listSessions(
) async throws -> AppwriteModels.SessionList {
let apiPath: String = "/account/sessions"
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.SessionList = { response in
return AppwriteModels.SessionList.from(map: response as! [String: Any])
}
return try await client.call(
method: "GET",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Delete Sessions
///
/// Delete all sessions from the user account and remove any sessions cookies
/// from the end client.
///
/// @throws Exception
/// @return array
///
open func deleteSessions(
) async throws -> Any {
let apiPath: String = "/account/sessions"
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
return try await client.call(
method: "DELETE",
path: apiPath,
headers: apiHeaders,
params: apiParams )
}
///
/// Create Anonymous Session
///
/// Use this endpoint to allow a new user to register an anonymous account in
/// your project. This route will also create a new session for the user. To
/// allow the new user to convert an anonymous account to a normal account, you
/// need to update its [email and
/// password](/docs/client/account#accountUpdateEmail) or create an [OAuth2
/// session](/docs/client/account#accountCreateOAuth2Session).
///
/// @throws Exception
/// @return array
///
open func createAnonymousSession(
) async throws -> AppwriteModels.Session {
let apiPath: String = "/account/sessions/anonymous"
let apiParams: [String: Any] = [:]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Session = { response in
return AppwriteModels.Session.from(map: response as! [String: Any])
}
return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Create Email Session
///
/// Allow the user to login into their account by providing a valid email and
/// password combination. This route will create a new session for the user.
///
/// A user is limited to 10 active sessions at a time by default. [Learn more
/// about session limits](/docs/authentication-security#limits).
///
/// @param String email
/// @param String password
/// @throws Exception
/// @return array
///
open func createEmailSession(
email: String,
password: String
) async throws -> AppwriteModels.Session {
let apiPath: String = "/account/sessions/email"
let apiParams: [String: Any?] = [
"email": email,
"password": password
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Session = { response in
return AppwriteModels.Session.from(map: response as! [String: Any])
}
return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Create Magic URL session
///
/// Sends the user an email with a secret key for creating a session. If the
/// provided user ID has not been registered, a new user will be created. When
/// the user clicks the link in the email, the user is redirected back to the
/// URL you provided with the secret key and userId values attached to the URL
/// query string. Use the query string parameters to submit a request to the
/// [PUT
/// /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession)
/// endpoint to complete the login process. The link sent to the user's email
/// address is valid for 1 hour. If you are on a mobile device you can leave
/// the URL parameter empty, so that the login completion will be handled by
/// your Appwrite instance by default.
///
/// A user is limited to 10 active sessions at a time by default. [Learn more
/// about session limits](/docs/authentication-security#limits).
///
///
/// @param String userId
/// @param String email
/// @param String url
/// @throws Exception
/// @return array
///
open func createMagicURLSession(
userId: String,
email: String,
url: String? = nil
) async throws -> AppwriteModels.Token {
let apiPath: String = "/account/sessions/magic-url"
let apiParams: [String: Any?] = [
"userId": userId,
"email": email,
"url": url
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Token = { response in
return AppwriteModels.Token.from(map: response as! [String: Any])
}
return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Create Magic URL session (confirmation)
///
/// Use this endpoint to complete creating the session with the Magic URL. Both
/// the **userId** and **secret** arguments will be passed as query parameters
/// to the redirect URL you have provided when sending your request to the
/// [POST
/// /account/sessions/magic-url](/docs/client/account#accountCreateMagicURLSession)
/// endpoint.
///
/// Please note that in order to avoid a [Redirect
/// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
/// the only valid redirect URLs are the ones from domains you have set when
/// adding your platforms in the console interface.
///
/// @param String userId
/// @param String secret
/// @throws Exception
/// @return array
///
open func updateMagicURLSession(
userId: String,
secret: String
) async throws -> AppwriteModels.Session {
let apiPath: String = "/account/sessions/magic-url"
let apiParams: [String: Any?] = [
"userId": userId,
"secret": secret
]
let apiHeaders: [String: String] = [
"content-type": "application/json"
]
let converter: (Any) -> AppwriteModels.Session = { response in
return AppwriteModels.Session.from(map: response as! [String: Any])
}
return try await client.call(
method: "PUT",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}
///
/// Create OAuth2 Session
///
/// Allow the user to login to their account using the OAuth2 provider of their
/// choice. Each OAuth2 provider should be enabled from the Appwrite console
/// first. Use the success and failure arguments to provide a redirect URL's
/// back to your app when login is completed.
///
/// If there is already an active session, the new session will be attached to
/// the logged-in account. If there are no active sessions, the server will
/// attempt to look for a user with the same email address as the email
/// received from the OAuth2 provider and attach the new session to the
/// existing user. If no matching user is found - the server will create a new
/// user.
///
/// A user is limited to 10 active sessions at a time by default. [Learn more
/// about session limits](/docs/authentication-security#limits).
///
///
/// @param String provider
/// @param String success
/// @param String failure
/// @param [String] scopes
/// @throws Exception
/// @return array
///
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)