Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using all possible token scopes by default for Web API requests breaks specific /web-api/ endpoints, and the /tokens endpoint a long with it #401

Open
Twinki14 opened this issue Sep 11, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@Twinki14
Copy link
Contributor

Twinki14 commented Sep 11, 2021

The only solution that currently exists is to completely avoid using any /web-api/ endpoint without specifying X-Spotify-Scope, upon calling /web-api/ without X-Spotify-Scope, a token for ALL scopes is generated, without a way to force generate a new token

Potential solution
Remove implicit token generation, and require a X-Spotify-Scope or scope in the /token request, no need to tweak the token store. Tokens will still be stored and cached, and the first token with the needed scope will still be retrieved from the token store list. The only difference is users will need to explicitly add a scope to their /web-api/ request. The issue of unsupported combinations of scopes will still remain though, so a key-value map for token storage might be a better solution. /token could take a third optional parameter, it being the key for the token store map. By default the scope could be used as the key in the store

Version/Commit
v1.6.1

@Twinki14 Twinki14 added the bug Something isn't working label Sep 11, 2021
@devgianlu
Copy link
Member

Thank you for the detailed issue, I'll get to this whenever I'll have time. PRs are appreciated.

@Twinki14
Copy link
Contributor Author

Twinki14 commented Sep 15, 2021

Thank you for the detailed issue, I'll get to this whenever I'll have time. PRs are appreciated.

It'd appear that something is off with key generation, using only a single scope when a key is generated internally via

    @NotNull
    public static JsonMercuryRequest<GenericJson> requestToken(@NotNull String deviceId, @NotNull String scope) {
        return new JsonMercuryRequest<>(RawMercuryRequest.get(String.format("hm://keymaster/token/authenticated?scope=%s&client_id=%s&device_id=%s", scope, KEYMASTER_CLIENT_ID, deviceId)), GenericJson.class);
    }

The returned access token doesn't work, the Spotify API gives me the same result as reported, it seems like I was wrong with compatibility between multiple scopes. This appears to be related to the actual token generation.

@devgianlu
Copy link
Member

This appears to be related to the actual token generation.

The API used for token generation is strictly an internal API which happens to work with the Web API sometimes.

@Twinki14
Copy link
Contributor Author

Twinki14 commented Sep 15, 2021

This appears to be related to the actual token generation.

The API used for token generation is strictly an internal API which happens to work with the Web API sometimes.

What would be the best route to take? I notice the length of keys generated via the web-console is quite different than the one being generated by librespot-java, is this something I could debug further, or would it be best to lay certain endpoints aside?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants