Last active
October 14, 2020 10:09
-
-
Save aalemi97/efed1d057de7220bb0acae4c524c2fb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func refreshToken(completion: @escaping (_ isSuccess: Bool) -> Void) { | |
guard let apiKey = UserDefaultsManager.shared.getUserCredentials().apiKey, | |
let secretKey = UserDefaultsManager.shared.getUserCredentials().secretKey else { return } | |
let parameters = ["grant_type": "client_credentials", "client_id": apiKey, "client_secret": secretKey] | |
AF.request(authorize, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in | |
if let data = response.data, let token = (try? JSONSerialization.jsonObject(with: data, options: []) | |
as? [String: Any])?["access_token"] as? String { | |
UserDefaultsManager.shared.setToken(token: token) | |
print("\nRefresh token completed successfully. New token is: \(token)\n") | |
completion(true) | |
} else { | |
completion(false) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment