@@ -98,7 +98,9 @@ expect fun getSpotifyPkceCodeChallenge(codeVerifier: String): String
98
98
99
99
/* *
100
100
* Instantiate a new [SpotifyImplicitGrantApi] using a Spotify [clientId], [redirectUri], and [token] retrieved from the implicit
101
- * grant flow
101
+ * grant flow.
102
+ *
103
+ * Use case: I have a token obtained after implicit grant authorization.
102
104
*
103
105
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
104
106
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
@@ -145,6 +147,10 @@ fun spotifyImplicitGrantApi(
145
147
/* *
146
148
* Instantiate a new [SpotifyAppApiBuilder] using a Spotify [clientId] and [clientSecret]
147
149
*
150
+ * Use case: I am using the client credentials flow.
151
+ * I only need access to public Spotify API endpoints, don't have an existing token,
152
+ * and don't want to deal with advanced configuration.
153
+ *
148
154
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
149
155
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
150
156
* @param options Override default API options such as the cache limit
@@ -163,6 +169,10 @@ fun spotifyAppApi(
163
169
* Instantiate a new [SpotifyAppApiBuilder] using a Spotify [clientId] and [clientSecret], with the ability to configure
164
170
* the api settings by providing a builder initialization [block]
165
171
*
172
+ * Use case: I am using the client credentials flow.
173
+ * I only need access to public Spotify API endpoints, might have an existing token,
174
+ * and might want to deal with advanced configuration.
175
+ *
166
176
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
167
177
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
168
178
* @param block Api settings block
@@ -183,6 +193,10 @@ fun spotifyAppApi(
183
193
/* *
184
194
* Instantiate a new [SpotifyAppApiBuilder] using a [Token]
185
195
*
196
+ * Use case: I am using the client credentials flow.
197
+ * I only need access to public Spotify API endpoints, I have an existing token,
198
+ * and I don't want to deal with advanced configuration.
199
+ *
186
200
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
187
201
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
188
202
* @param apiToken The access token that will be associated with the built API instance
@@ -212,12 +226,17 @@ fun spotifyAppApi(
212
226
*
213
227
* **Note**: You **must** provide your app credentials in the [SpotifyAppApiBuilder.credentials] block
214
228
*
229
+ * Use case: I am using the client credentials flow.
230
+ * I only need access to public Spotify API endpoints, and I want to use the [SpotifyAppApiBuilder] DSL
231
+ * to configure everything myself.
232
+ *
215
233
* @param block Api settings block
216
234
*
217
235
* @return Configurable [SpotifyAppApiBuilder] that, when built, creates a new [SpotifyAppApi]
218
236
*/
219
237
fun spotifyAppApi (block : SpotifyAppApiBuilder .() -> Unit ) = SpotifyAppApiBuilder ().apply (block)
220
238
239
+
221
240
// Client Api Builders
222
241
/*
223
242
____________________________
@@ -238,6 +257,10 @@ fun spotifyAppApi(block: SpotifyAppApiBuilder.() -> Unit) = SpotifyAppApiBuilder
238
257
* **Note**: If trying to build [SpotifyClientApi], you **must** provide client authorization in the [SpotifyClientApiBuilder.authorization]
239
258
* block
240
259
*
260
+ * Use case: I am using the client authorization flow.
261
+ * I want access to both public and client Spotify API endpoints, and I want
262
+ * to configure authorization and other settings myself.
263
+ *
241
264
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
242
265
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
243
266
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
@@ -261,6 +284,9 @@ fun spotifyClientApi(
261
284
/* *
262
285
* Instantiate a new [SpotifyClientApiBuilder] using a [Token]
263
286
*
287
+ * Use case: I am using the client authorization flow.
288
+ * I want access to both public and client Spotify API endpoints, I have an existing token,
289
+ * and I might want to configure api options.
264
290
*
265
291
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
266
292
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
@@ -293,6 +319,9 @@ fun spotifyClientApi(
293
319
/* *
294
320
* Instantiate a new [SpotifyClientApiBuilder] using an [authCode]
295
321
*
322
+ * Use case: I am using the client authorization flow.
323
+ * I want access to both public and client Spotify API endpoints, I have an authorization code,
324
+ * and I might want to configure api options.
296
325
*
297
326
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
298
327
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
@@ -327,6 +356,10 @@ fun spotifyClientApi(
327
356
* with an existing [SpotifyUserAuthorization] and with the ability to configure the api settings by providing a
328
357
* builder initialization [block]
329
358
*
359
+ * Use case: I am using the client authorization flow.
360
+ * I want access to both public and client Spotify API endpoints and I want to configure [authorization]
361
+ * and [options] without using the DSL.
362
+ *
330
363
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
331
364
* @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
332
365
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
@@ -340,12 +373,11 @@ fun spotifyClientApi(
340
373
*/
341
374
fun spotifyClientApi (
342
375
clientId : String ,
343
- clientSecret : String ,
376
+ clientSecret : String? ,
344
377
redirectUri : String ,
345
378
authorization : SpotifyUserAuthorization ,
346
- options : SpotifyApiOptionsBuilder ? = null,
347
- block : SpotifyClientApiBuilder .() -> Unit = {}
348
- ) = SpotifyClientApiBuilder ().apply (block).apply {
379
+ options : SpotifyApiOptionsBuilder ? = null
380
+ ) = SpotifyClientApiBuilder ().apply {
349
381
credentials {
350
382
this .clientId = clientId
351
383
this .clientSecret = clientSecret
@@ -361,6 +393,10 @@ fun spotifyClientApi(
361
393
* **Note**: If trying to build [SpotifyClientApi], you **must** provide client authorization in the [SpotifyClientApiBuilder.authorization]
362
394
* block
363
395
*
396
+ * Use case: I am using the client authorization flow.
397
+ * I want access to both public and client Spotify API endpoints and I want to handle configuration
398
+ * via the DSL myself.
399
+ *
364
400
* @param block Api settings block
365
401
*
366
402
* @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
@@ -383,11 +419,13 @@ fun spotifyClientApi(block: SpotifyClientApiBuilder.() -> Unit) = SpotifyClientA
383
419
/* *
384
420
* Instantiate a new [SpotifyClientApiBuilder] using an [authCode] and [codeVerifier]. This is for **PKCE authorization**.
385
421
*
422
+ * Use case: I am using the PKCE client authorization flow.
423
+ * I want access to both public and client Spotify API endpoints, I have an existing api [token], and I might
424
+ * want to set api [options] without using the DSL.
386
425
*
387
426
* @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
388
- * @param clientSecret Spotify [client secret](https://developer.spotify.com/documentation/general/guides/app-settings/)
389
427
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
390
- * @param authCode The authorization code retrieved after OAuth authorization
428
+ * @param token Api token retrieved using PKCE authorization flow.
391
429
* @param codeVerifier Your code verifier plaintext.
392
430
* @param options Override default API options such as the cache limit
393
431
*
@@ -396,7 +434,7 @@ fun spotifyClientApi(block: SpotifyClientApiBuilder.() -> Unit) = SpotifyClientA
396
434
fun spotifyClientPkceApi (
397
435
clientId : String? ,
398
436
redirectUri : String? ,
399
- authCode : String ,
437
+ token : Token ,
400
438
codeVerifier : String ,
401
439
options : SpotifyApiOptionsBuilder ? = null
402
440
) = SpotifyClientApiBuilder ().apply {
@@ -405,6 +443,41 @@ fun spotifyClientPkceApi(
405
443
this .redirectUri = redirectUri
406
444
}
407
445
446
+ authentication {
447
+ this .token = token
448
+ pkceCodeVerifier = codeVerifier
449
+ }
450
+
451
+ options?.let { this .options = it.build() }
452
+ }
453
+
454
+ /* *
455
+ * Instantiate a new [SpotifyClientApiBuilder] using a [token] and [codeVerifier]. This is for **PKCE authorization**.
456
+ *
457
+ * Use case: I am using the PKCE client authorization flow.
458
+ * I want access to both public and client Spotify API endpoints, I have an authorization code, and I might
459
+ * want to set api [options] without using the DSL.
460
+ *
461
+ * @param clientId Spotify [client id](https://developer.spotify.com/documentation/general/guides/app-settings/)
462
+ * @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
463
+ * @param authCode The authorization code retrieved after OAuth authorization
464
+ * @param codeVerifier Your code verifier plaintext.
465
+ * @param options Override default API options such as the cache limit
466
+ *
467
+ * @return Configurable [SpotifyClientApiBuilder] that, when built, creates a new [SpotifyClientApi]
468
+ */
469
+ fun spotifyClientPkceApi (
470
+ clientId : String? ,
471
+ redirectUri : String? ,
472
+ authCode : String ,
473
+ codeVerifier : String ,
474
+ options : SpotifyApiOptionsBuilder ? = null
475
+ ) = SpotifyClientApiBuilder ().apply {
476
+ credentials {
477
+ this .clientId = clientId
478
+ this .redirectUri = redirectUri
479
+ }
480
+
408
481
authentication {
409
482
authorizationCode = authCode
410
483
pkceCodeVerifier = codeVerifier
@@ -413,6 +486,7 @@ fun spotifyClientPkceApi(
413
486
options?.let { this .options = it.build() }
414
487
}
415
488
489
+
416
490
/* *
417
491
* Spotify API builder
418
492
*/
0 commit comments