Skip to content

Commit 2be92b9

Browse files
Jiankai ZhengJiankai Zheng
authored andcommitted
Merge remote-tracking branch 'origin/main' into main
2 parents ae96b36 + 6916491 commit 2be92b9

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# Spotify Web API Wrapper
44
Spotify API wrapper for Java
55

6+
## Guides
7+
Use the following guides provided by Spotify to use this library:
8+
- [Authorization Guide](https://developer.spotify.com/documentation/general/guides/authorization-guide/)
9+
- [Web API](https://developer.spotify.com/documentation/web-api/reference/)
10+
611
## Example usages
712
### Client Credentials Flow
813
The Client Credentials flow is used in server-to-server authentication. Only endpoints that do not access user information can be accessed.
@@ -52,12 +57,54 @@ AuthorizationCodeFlowTokenResponse token = authorizationRequestToken
5257
"AUTHORIZATION CODE",
5358
"REDIRECT URI");
5459
```
60+
61+
### Authorization Code Flow with Proof Key for Code Exchange (PKCE)
62+
The authorization code flow with PKCE is the best option for mobile and desktop applications where it is unsafe to store your client secret. It provides your app with an access token that can be refreshed. For further information about this flow, see [IETF RFC-7636](https://tools.ietf.org/html/rfc7636).
63+
64+
The first step to get an access and refresh token through the Authorization PKCE Code Flow is to build an url.
65+
```java
66+
AuthorizationCodeFlowPKCE pkce = new AuthorizationCodeFlowPKCE.Builder()
67+
.setClientId("CLIENT ID")
68+
.setRedirectUri("REDIRECT URI")
69+
.setResponseType("code")
70+
.setScopes(Arrays.asList(
71+
AuthorizationScope.APP_REMOTE_CONTROL,
72+
AuthorizationScope.PLAYLIST_MODIFY_PRIVATE))
73+
.setCodeChallengeMethod("S256")
74+
.setCodeChallenge("CODE CHALLENGE")
75+
.setState("STATE")
76+
.build();
77+
```
78+
79+
The above code will result in the following url.
80+
```
81+
https://accounts.spotify.com/authorize?client_id=CLIENT ID&response_type=code&redirect_uri=REDIRECT URI&scope=app-remote-control playlist-modify-private&state=STATE&code_challenge_method=S256&code_challenge=CODE CHALLENGE
82+
```
83+
By visiting the url it will display a prompt to authorize access within the given scopes. Authorizing access will redirect the user to the given redirect uri. An authorization code will also be returned, it can be found as a query parameter in the redirect uri. Use this authorization code for the second step.
84+
85+
For the second step the following values need to be provided:
86+
- Client ID
87+
- Authorization Code (the code that got returned when redirected from spotify)
88+
- Redirect Uri (the redirect uri that was given in the first step)
89+
- Code verifier (the one that was generated at the first step)
90+
91+
```java
92+
AuthorizationPKCERequestToken a = new AuthorizationPKCERequestToken();
93+
final String accessToken = a.getAccessAndRefreshToken(
94+
"CLIENT ID",
95+
"CODE",
96+
"REDIRECT URI",
97+
"CODE VERIFIER")
98+
.getAccessToken();
99+
```
100+
### Using access token
55101
The `AuthorizationCodeFlowTokenResponse` contains the access and refresh token. The access and refresh token can be used to access api endpoints.
56102
```java
57103
SpotifyApi spotifyApi = new SpotifyApi("ACCESS TOKEN", "REFRESH TOKEN");
58104
AlbumFull albumFull = spotifyApi.getAlbum("ALBUM ID");
59105
```
60106

107+
### Refreshing access token
61108
When the access token has expired it can be refreshed using `AuthorizationRefreshToken`
62109
```java
63110
AuthorizationCodeFlowTokenResponse token = authorizationRefreshToken
@@ -179,8 +226,8 @@ This is the most recent coverage in the repository. The marked endpoints may not
179226
- - [x] Reorder a Playlist's Items
180227
- - [x] Replace a Playlist's Items
181228
- - [x] Change a Playlist's Details
182-
- [ ] Search
183-
- - [ ] Search for an item
229+
- [x] Search
230+
- - [x] Search for an item
184231
- [x] Tracks
185232
- - [x] Get a Track
186233
- - [x] Get Several Tracks

0 commit comments

Comments
 (0)