@@ -5,19 +5,13 @@ public class VKBMWConnectedDriveAPI: VKVehicleAPIBase<VKBMWConnectedDriveAPI.Cre
5
5
case authenticatingWithoutCredentials
6
6
case cantEncodeRequestBody
7
7
case invalidAuthConfig
8
- case authResponseNotHTTP
9
- case authResponseMissingLocation(
10
- status: Int ,
11
- headers: [ AnyHashable : Any ] ,
12
- responseData: Data ,
13
- responseString: String ?
14
- )
15
8
case cantDecodeAuthResponseLocation( location: String )
16
9
case authResponseMissingToken( location: String )
17
10
case authResponseMissingExpires( location: String )
18
11
case invalidHost
19
12
case responseInvalid
20
13
case invalidURL
14
+ case invalidRedirectTo( redirectTo: String )
21
15
}
22
16
23
17
public struct Credentials : Codable {
@@ -107,7 +101,7 @@ public class VKBMWConnectedDriveAPI: VKVehicleAPIBase<VKBMWConnectedDriveAPI.Cre
107
101
throw APIError . cantEncodeRequestBody
108
102
}
109
103
let url = try pathToURL ( path: authConfig. endpoints. authenticate)
110
- let response : AuthResponse = try await VKHTTP . request (
104
+ let response : VKHTTP . Response < AuthResponse > = try await VKHTTP . request (
111
105
url,
112
106
method: " POST " ,
113
107
body: body. data ( using: . utf8) ,
@@ -118,8 +112,12 @@ public class VKBMWConnectedDriveAPI: VKVehicleAPIBase<VKBMWConnectedDriveAPI.Cre
118
112
" Referer " : " https://login.bmwusa.com/ " ,
119
113
" User-Agent " : " Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36 "
120
114
]
121
- ) . data
122
- return String ( response. redirectTo. dropFirst ( " redirect_uri= " . count) )
115
+ )
116
+ let redirectTo = response. data. redirectTo
117
+ if !redirectTo. starts ( with: " redirect_uri= " ) {
118
+ throw APIError . invalidRedirectTo ( redirectTo: redirectTo)
119
+ }
120
+ return String ( redirectTo. dropFirst ( " redirect_uri= " . count) )
123
121
}
124
122
125
123
private func authenticate( ) async throws -> Session {
0 commit comments