Add support for OAuth authentication strategy #931
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Spotify deprecated authentication with username and password and this authentication strategy no longer works in librespot-java resulting in
BadCredentials
exception (#921).This PR adds OAuth as new authentication strategy as replacement. It's basically a backport of the PR librespot-org/librespot#1309 from the related librespot project.
It adds all the OAuth logic as a new class in the lib module which is capable of providing LoginCredentials of type AUTHENTICATION_SPOTIFY_TOKEN by following the Authorization Code with PKCE Flow.
The session with token authentication can not be used with the keymaster which is why it does a reconnect with the ReusableAuthCredentials, same as in librespot.
To avoid having to authenticate with OAuth with every single run, it is intended to be used together with having storeCredentials enabled and it will default to use the stored credentials if they exist.
The OAuth class provides the full authentication flow with the
flow
method including running a simple callback server suitable for a local terminal-based environments which can be used as reference and the player module and FileConfiguration is also adjusted to support it.The required steps for OAuth can also be done manually which makes it possible to integrate into non-terminal-based environments, such as Android in my case, in the following way:
Thanks a lot for the library! I know it is no longer actively maintained but I hope we can keep it working :)
Fixes #921