@@ -28,9 +28,24 @@ import kotlinx.serialization.json.Json
28
28
* @param redirectUri Spotify [redirect uri](https://developer.spotify.com/documentation/general/guides/app-settings/)
29
29
* @param isImplicitGrantFlow Whether the authorization url should be for the Implicit Grant flow, otherwise for Authorization Code flo
30
30
* @param shouldShowDialog If [isImplicitGrantFlow] is true, whether or not to force the user to approve the app again if they’ve already done so.
31
+ * @param state This provides protection against attacks such as cross-site request forgery.
31
32
*/
32
- fun getSpotifyAuthorizationUrl (vararg scopes : SpotifyScope , clientId : String , redirectUri : String , isImplicitGrantFlow : Boolean = false, shouldShowDialog : Boolean = false): String {
33
- return SpotifyApi .getAuthUrlFull(* scopes, clientId = clientId, redirectUri = redirectUri, isImplicitGrantFlow = isImplicitGrantFlow, shouldShowDialog = shouldShowDialog)
33
+ fun getSpotifyAuthorizationUrl (
34
+ vararg scopes : SpotifyScope ,
35
+ clientId : String ,
36
+ redirectUri : String ,
37
+ isImplicitGrantFlow : Boolean = false,
38
+ shouldShowDialog : Boolean = false,
39
+ state : String? = null
40
+ ): String {
41
+ return SpotifyApi .getAuthUrlFull(
42
+ * scopes,
43
+ clientId = clientId,
44
+ redirectUri = redirectUri,
45
+ isImplicitGrantFlow = isImplicitGrantFlow,
46
+ shouldShowDialog = shouldShowDialog,
47
+ state = state
48
+ )
34
49
}
35
50
36
51
// ==============================================
@@ -536,9 +551,10 @@ interface ISpotifyClientApiBuilder : ISpotifyApiBuilder<SpotifyClientApi, Spotif
536
551
* Create a Spotify authorization URL from which API access can be obtained
537
552
*
538
553
* @param scopes The scopes that the application should have access to
554
+ * @param state This provides protection against attacks such as cross-site request forgery.
539
555
* @return Authorization URL that can be used in a browser
540
556
*/
541
- fun getAuthorizationUrl (vararg scopes : SpotifyScope ): String
557
+ fun getAuthorizationUrl (vararg scopes : SpotifyScope , state : String? = null ): String
542
558
}
543
559
544
560
/* *
@@ -549,9 +565,14 @@ class SpotifyClientApiBuilder(
549
565
override var authorization : SpotifyUserAuthorization = SpotifyUserAuthorizationBuilder ().build(),
550
566
override var options : SpotifyApiOptions = SpotifyApiOptionsBuilder ().build()
551
567
) : ISpotifyClientApiBuilder {
552
- override fun getAuthorizationUrl (vararg scopes : SpotifyScope ): String {
568
+ override fun getAuthorizationUrl (vararg scopes : SpotifyScope , state : String? ): String {
553
569
require(credentials.redirectUri != null && credentials.clientId != null ) { " You didn't specify a redirect uri or client id in the credentials block!" }
554
- return SpotifyApi .getAuthUrlFull(* scopes, clientId = credentials.clientId!! , redirectUri = credentials.redirectUri!! )
570
+ return SpotifyApi .getAuthUrlFull(
571
+ * scopes,
572
+ clientId = credentials.clientId!! ,
573
+ redirectUri = credentials.redirectUri!! ,
574
+ state = state
575
+ )
555
576
}
556
577
557
578
override suspend fun suspendBuild (): SpotifyClientApi {
0 commit comments