01. 인가 코드 받기

전체적인 흐름이 구글과 매우 유사하다.

GET <https://accounts.spotify.com/authorize>

Query Parameter

Request

GET <https://accounts.spotify.com/authorize>?
client_id={client_id}&
response_type=code&
redirect_uri={redirect uri}&
scope=user-read-private user-read-email&
state=12345

Response

https://{redirect uri}?code={인가 code 정보}&state={}

02. 액세스 토큰 요청

POST <https://accounts.spotify.com/api/token>

Request Body Parameter

Request

POST <https://accounts.spotify.com/api/token>
Content-Type: application/x-www-form-urlencoded

code={인가 code 정보}
client_id={client_id}&
client_secret={client_secret}&
redirect_uri={redirect uri}&
grant_type=authorization_code

핵심은 Content-Typeapplication/x-www-form-urlencoded이다. google과 동일한데 restTemplate.postForObject 메소드를 적용하면 지원하지 않는 media-type으로 415코드를 던진다. 우리 프로젝트에서는 프론트에서 token 까지 생성하여 전달받을 예정이기 때문에 간단히 조사하였다.

Response

{
    "access_token": "{access_token}",
    "token_type": "Bearer",
    "scope": "user-read-email user-read-private",
    "expires_in": "3600",
    "refresh_token": "{refresh_token}"
}

03. playlist 목록 API