@@ -21,18 +21,39 @@ public struct ParseSpotify<AuthenticatedUser: ParseUser>: ParseAuthentication {
21
21
enum AuthenticationKeys : String , Codable {
22
22
case id
23
23
case accessToken = " access_token "
24
-
24
+ case clientId = " client_id "
25
+ case expiresIn = " expires_in "
26
+ case refreshToken = " refresh_token "
25
27
/// Properly makes an authData dictionary with the required keys.
26
28
/// - parameter id: Required id for the user.
27
29
/// - parameter accessToken: Required access token for Spotify.
30
+ /// - parameter clientId: Optional client id for Spotify.
31
+ /// - parameter expiresIn: Optional expiration in seconds for Spotify.
32
+ /// - parameter refreshToken: Optional refresh token for Spotify.
28
33
/// - returns: authData dictionary.
29
34
func makeDictionary( id: String ,
30
- accessToken: String ) -> [ String : String ] {
35
+ accessToken: String ,
36
+ clientId: String ? = nil ,
37
+ expiresIn: Int ? = nil ,
38
+ refreshToken: String ? = nil ) -> [ String : String ] {
31
39
32
- let returnDictionary = [
40
+ var returnDictionary = [
33
41
AuthenticationKeys . id. rawValue: id,
34
42
AuthenticationKeys . accessToken. rawValue: accessToken
35
43
]
44
+ if let clientId = clientId {
45
+ returnDictionary [ AuthenticationKeys . clientId. rawValue] = clientId
46
+ }
47
+ if let expiresIn = expiresIn,
48
+ let expirationDate = Calendar . current. date ( byAdding: . second,
49
+ value: expiresIn,
50
+ to: Date ( ) ) {
51
+ let dateString = ParseCoding . dateFormatter. string ( from: expirationDate)
52
+ returnDictionary [ AuthenticationKeys . expiresIn. rawValue] = dateString
53
+ }
54
+ if let refreshToken = refreshToken {
55
+ returnDictionary [ AuthenticationKeys . refreshToken. rawValue] = refreshToken
56
+ }
36
57
return returnDictionary
37
58
}
38
59
@@ -62,20 +83,28 @@ public extension ParseSpotify {
62
83
Login a `ParseUser` *asynchronously* using Spotify authentication.
63
84
- parameter id: The **Spotify profile id** from **Spotify**.
64
85
- parameter accessToken: Required **access_token** from **Spotify**.
86
+ - parameter clientId: Optional **client_id** from **Spotify**.
87
+ - parameter expiresIn: Optional **expires_in** in seconds from **Spotify**.
88
+ - parameter refreshToken: Optional **refresh_token** from **Spotify**.
65
89
- parameter options: A set of header options sent to the server. Defaults to an empty set.
66
90
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
67
91
- parameter completion: The block to execute.
68
92
*/
69
93
func login( id: String ,
70
94
accessToken: String ,
95
+ clientId: String ? = nil ,
96
+ expiresIn: Int ? = nil ,
97
+ refreshToken: String ? = nil ,
71
98
options: API . Options = [ ] ,
72
99
callbackQueue: DispatchQueue = . main,
73
100
completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
74
101
75
102
let spotifyAuthData = AuthenticationKeys . id
76
103
. makeDictionary ( id: id,
77
- accessToken: accessToken)
78
- // print(spotifyAuthData)
104
+ accessToken: accessToken,
105
+ clientId: clientId,
106
+ expiresIn: expiresIn,
107
+ refreshToken: refreshToken)
79
108
login ( authData: spotifyAuthData,
80
109
options: options,
81
110
callbackQueue: callbackQueue,
@@ -108,18 +137,27 @@ public extension ParseSpotify {
108
137
Link the *current* `ParseUser` *asynchronously* using Spotify authentication.
109
138
- parameter id: The **Spotify profile id** from **Spotify**.
110
139
- parameter accessToken: Required **access_token** from **Spotify**.
140
+ - parameter clientId: Optional **client_id** from **Spotify**.
141
+ - parameter expiresIn: Optional **expires_in** in seconds from **Spotify**.
142
+ - parameter refreshToken: Optional **refresh_token** from **Spotify**.
111
143
- parameter options: A set of header options sent to the server. Defaults to an empty set.
112
144
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
113
145
- parameter completion: The block to execute.
114
146
*/
115
147
func link( id: String ,
116
148
accessToken: String ,
149
+ clientId: String ? = nil ,
150
+ expiresIn: Int ? = nil ,
151
+ refreshToken: String ? = nil ,
117
152
options: API . Options = [ ] ,
118
153
callbackQueue: DispatchQueue = . main,
119
154
completion: @escaping ( Result < AuthenticatedUser , ParseError > ) -> Void ) {
120
155
let spotifyAuthData = AuthenticationKeys . id
121
156
. makeDictionary ( id: id,
122
- accessToken: accessToken)
157
+ accessToken: accessToken,
158
+ clientId: clientId,
159
+ expiresIn: expiresIn,
160
+ refreshToken: refreshToken)
123
161
link ( authData: spotifyAuthData,
124
162
options: options,
125
163
callbackQueue: callbackQueue,
0 commit comments