forked from openedx-unsupported/edx-app-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginApi.swift
37 lines (33 loc) · 1.17 KB
/
LoginApi.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
//
// LoginApi.swift
// edX
//
// Created by Christopher Lee on 5/13/16.
// Copyright © 2016 edX. All rights reserved.
//
public struct LoginAPI {
static func refreshTokenDeserializer(response: HTTPURLResponse, json: JSON) -> Result<OEXAccessToken> {
guard response.httpStatusCode.is2xx,
let dictionary = json.dictionaryObject else {
return .failure(NetworkManager.unknownError)
}
let token = OEXAccessToken(tokenDetails: dictionary)
return .success(token)
}
// Retrieves a new access token by using the refresh token.
public static func requestTokenWithRefreshToken(refreshToken: String, clientId: String) -> NetworkRequest<OEXAccessToken> {
let body = [
"refresh_token": refreshToken,
"client_id": clientId,
"grant_type": "refresh_token",
"token_type": "jwt",
"asymmetric_jwt": "true"
]
return NetworkRequest(
method: .POST,
path: "/oauth2/access_token/",
body: RequestBody.formEncoded(body),
deserializer: .jsonResponse(refreshTokenDeserializer)
)
}
}