@@ -24,22 +24,22 @@ import Foundation
24
24
25
25
struct Auth0Authentication : Authentication {
26
26
let clientId : String
27
- let url : NSURL
27
+ let url : URL
28
28
var telemetry : Telemetry
29
29
var logger : Logger ?
30
30
31
- let session : NSURLSession
31
+ let session : URLSession
32
32
33
- init ( clientId: String , url: NSURL , session: NSURLSession = NSURLSession . sharedSession ( ) , telemetry: Telemetry = Telemetry ( ) ) {
33
+ init ( clientId: String , url: URL , session: URLSession = URLSession . shared , telemetry: Telemetry = Telemetry ( ) ) {
34
34
self . clientId = clientId
35
35
self . url = url
36
36
self . session = session
37
37
self . telemetry = telemetry
38
38
}
39
39
40
- func login( usernameOrEmail username: String , password: String , multifactorCode: String ? , connection: String , scope: String , parameters: [ String : AnyObject ] ) -> Request < Credentials , AuthenticationError > {
41
- let resourceOwner = NSURL ( string: " /oauth/ro " , relativeToURL : self . url) !
42
- var payload : [ String : AnyObject ] = [
40
+ func login( usernameOrEmail username: String , password: String , multifactorCode: String ? , connection: String , scope: String , parameters: [ String : Any ] ) -> Request < Credentials , AuthenticationError > {
41
+ let resourceOwner = URL ( string: " /oauth/ro " , relativeTo : self . url) !
42
+ var payload : [ String : Any ] = [
43
43
" username " : username,
44
44
" password " : password,
45
45
" connection " : connection,
@@ -53,8 +53,8 @@ struct Auth0Authentication: Authentication {
53
53
}
54
54
55
55
56
- func createUser( email email : String , username: String ? = nil , password: String , connection: String , userMetadata: [ String : AnyObject ] ? = nil ) -> Request < DatabaseUser , AuthenticationError > {
57
- var payload : [ String : AnyObject ] = [
56
+ func createUser( email: String , username: String ? = nil , password: String , connection: String , userMetadata: [ String : Any ] ? = nil ) -> Request < DatabaseUser , AuthenticationError > {
57
+ var payload : [ String : Any ] = [
58
58
" email " : email,
59
59
" password " : password,
60
60
" connection " : connection,
@@ -63,81 +63,81 @@ struct Auth0Authentication: Authentication {
63
63
payload [ " username " ] = username
64
64
payload [ " user_metadata " ] = userMetadata
65
65
66
- let createUser = NSURL ( string: " /dbconnections/signup " , relativeToURL : self . url) !
66
+ let createUser = URL ( string: " /dbconnections/signup " , relativeTo : self . url) !
67
67
return Request ( session: session, url: createUser, method: " POST " , handle: databaseUser, payload: payload, logger: self . logger, telemetry: self . telemetry)
68
68
}
69
69
70
- func resetPassword( email email : String , connection: String ) -> Request < Void , AuthenticationError > {
70
+ func resetPassword( email: String , connection: String ) -> Request < Void , AuthenticationError > {
71
71
let payload = [
72
72
" email " : email,
73
73
" connection " : connection,
74
74
" client_id " : self . clientId
75
75
]
76
- let resetPassword = NSURL ( string: " /dbconnections/change_password " , relativeToURL : self . url) !
76
+ let resetPassword = URL ( string: " /dbconnections/change_password " , relativeTo : self . url) !
77
77
return Request ( session: session, url: resetPassword, method: " POST " , handle: noBody, payload: payload, logger: self . logger, telemetry: self . telemetry)
78
78
}
79
79
80
- func signUp( email email : String , username: String ? = nil , password: String , connection: String , userMetadata: [ String : AnyObject ] ? , scope: String , parameters: [ String : AnyObject ] ) -> ConcatRequest < DatabaseUser , Credentials , AuthenticationError > {
80
+ func signUp( email: String , username: String ? = nil , password: String , connection: String , userMetadata: [ String : Any ] ? , scope: String , parameters: [ String : Any ] ) -> ConcatRequest < DatabaseUser , Credentials , AuthenticationError > {
81
81
let first = createUser ( email: email, username: username, password: password, connection: connection, userMetadata: userMetadata)
82
82
let second = login ( usernameOrEmail: email, password: password, connection: connection, scope: scope, parameters: parameters)
83
83
return ConcatRequest ( first: first, second: second)
84
84
}
85
85
86
- func startPasswordless( email email : String , type: PasswordlessType , connection: String , parameters: [ String : AnyObject ] ) -> Request < Void , AuthenticationError > {
87
- var payload : [ String : AnyObject ] = [
86
+ func startPasswordless( email: String , type: PasswordlessType , connection: String , parameters: [ String : Any ] ) -> Request < Void , AuthenticationError > {
87
+ var payload : [ String : Any ] = [
88
88
" email " : email,
89
89
" connection " : connection,
90
90
" send " : type. rawValue,
91
91
" client_id " : self . clientId,
92
92
]
93
- if case . WebLink = type where !parameters. isEmpty {
93
+ if case . WebLink = type , !parameters. isEmpty {
94
94
payload [ " authParams " ] = parameters
95
95
}
96
96
97
- let start = NSURL ( string: " /passwordless/start " , relativeToURL : self . url) !
97
+ let start = URL ( string: " /passwordless/start " , relativeTo : self . url) !
98
98
return Request ( session: session, url: start, method: " POST " , handle: noBody, payload: payload, logger: self . logger, telemetry: self . telemetry)
99
99
}
100
100
101
- func startPasswordless( phoneNumber phoneNumber : String , type: PasswordlessType , connection: String ) -> Request < Void , AuthenticationError > {
102
- let payload : [ String : AnyObject ] = [
101
+ func startPasswordless( phoneNumber: String , type: PasswordlessType , connection: String ) -> Request < Void , AuthenticationError > {
102
+ let payload : [ String : Any ] = [
103
103
" phone_number " : phoneNumber,
104
104
" connection " : connection,
105
105
" send " : type. rawValue,
106
106
" client_id " : self . clientId,
107
107
]
108
- let start = NSURL ( string: " /passwordless/start " , relativeToURL : self . url) !
108
+ let start = URL ( string: " /passwordless/start " , relativeTo : self . url) !
109
109
return Request ( session: session, url: start, method: " POST " , handle: noBody, payload: payload, logger: self . logger, telemetry: self . telemetry)
110
110
}
111
111
112
- func tokenInfo( token token : String ) -> Request < Profile , AuthenticationError > {
113
- let payload : [ String : AnyObject ] = [ " id_token " : token]
114
- let tokenInfo = NSURL ( string: " /tokeninfo " , relativeToURL : self . url) !
112
+ func tokenInfo( token: String ) -> Request < Profile , AuthenticationError > {
113
+ let payload : [ String : Any ] = [ " id_token " : token]
114
+ let tokenInfo = URL ( string: " /tokeninfo " , relativeTo : self . url) !
115
115
return Request ( session: session, url: tokenInfo, method: " POST " , handle: authenticationObject, payload: payload, logger: self . logger, telemetry: self . telemetry)
116
116
}
117
117
118
- func userInfo( token token : String ) -> Request < Profile , AuthenticationError > {
119
- let userInfo = NSURL ( string: " /userinfo " , relativeToURL : self . url) !
118
+ func userInfo( token: String ) -> Request < Profile , AuthenticationError > {
119
+ let userInfo = URL ( string: " /userinfo " , relativeTo : self . url) !
120
120
return Request ( session: session, url: userInfo, method: " GET " , handle: authenticationObject, headers: [ " Authorization " : " Bearer \( token) " ] , logger: self . logger, telemetry: self . telemetry)
121
121
}
122
122
123
- func loginSocial( token token : String , connection: String , scope: String , parameters: [ String : AnyObject ] ) -> Request < Credentials , AuthenticationError > {
124
- var payload : [ String : AnyObject ] = [
123
+ func loginSocial( token: String , connection: String , scope: String , parameters: [ String : Any ] ) -> Request < Credentials , AuthenticationError > {
124
+ var payload : [ String : Any ] = [
125
125
" access_token " : token,
126
126
" connection " : connection,
127
127
" scope " : scope,
128
128
" client_id " : self . clientId,
129
129
]
130
130
parameters. forEach { key, value in payload [ key] = value }
131
- let accessToken = NSURL ( string: " /oauth/access_token " , relativeToURL : self . url) !
131
+ let accessToken = URL ( string: " /oauth/access_token " , relativeTo : self . url) !
132
132
return Request ( session: session, url: accessToken, method: " POST " , handle: authenticationObject, payload: payload, logger: self . logger, telemetry: self . telemetry)
133
133
}
134
134
135
- func tokenExchange( withParameters parameters: [ String : AnyObject ] ) -> Request < Credentials , AuthenticationError > {
136
- var payload : [ String : AnyObject ] = [
137
- " client_id " : self . clientId
135
+ func tokenExchange( withParameters parameters: [ String : Any ] ) -> Request < Credentials , AuthenticationError > {
136
+ var payload : [ String : Any ] = [
137
+ " client_id " : self . clientId,
138
138
]
139
139
parameters. forEach { payload [ $0] = $1 }
140
- let token = NSURL ( string: " /oauth/token " , relativeToURL : self . url) !
140
+ let token = URL ( string: " /oauth/token " , relativeTo : self . url) !
141
141
return Request ( session: session, url: token, method: " POST " , handle: authenticationObject, payload: payload, logger: self . logger, telemetry: self . telemetry)
142
142
}
143
143
@@ -146,7 +146,7 @@ struct Auth0Authentication: Authentication {
146
146
" code " : code,
147
147
" code_verifier " : codeVerifier,
148
148
" redirect_uri " : redirectURI,
149
- " grant_type " : " authorization_code "
149
+ " grant_type " : " authorization_code " ,
150
150
] )
151
151
}
152
152
}
0 commit comments