|
18 | 18 |
|
19 | 19 | import com.google.gson.JsonArray; |
20 | 20 | import com.google.gson.JsonObject; |
| 21 | +import com.google.protobuf.ByteString; |
| 22 | +import com.spotifyxp.deps.com.spotify.login5v3.Credentials; |
| 23 | +import com.spotifyxp.deps.com.spotify.login5v3.Login5; |
21 | 24 | import com.spotifyxp.deps.xyz.gianlu.librespot.common.Utils; |
22 | | -import com.spotifyxp.deps.xyz.gianlu.librespot.json.GenericJson; |
23 | 25 | import com.spotifyxp.deps.xyz.gianlu.librespot.mercury.MercuryClient; |
24 | | -import com.spotifyxp.deps.xyz.gianlu.librespot.mercury.MercuryRequests; |
25 | 26 | import com.spotifyxp.logging.ConsoleLoggingModules; |
26 | 27 | import org.jetbrains.annotations.NotNull; |
27 | 28 | import org.jetbrains.annotations.Nullable; |
28 | | - |
29 | 29 | import java.io.IOException; |
| 30 | +import java.security.NoSuchAlgorithmException; |
30 | 31 | import java.util.ArrayList; |
31 | 32 | import java.util.Arrays; |
32 | 33 | import java.util.List; |
@@ -64,8 +65,38 @@ public synchronized StoredToken getToken(@NotNull String... scopes) throws IOExc |
64 | 65 | } |
65 | 66 |
|
66 | 67 | ConsoleLoggingModules.debug("Token expired or not suitable, requesting again. {scopes: {}, oldToken: {}}", Arrays.asList(scopes), token); |
67 | | - GenericJson resp = session.mercury().sendSync(MercuryRequests.requestToken(session.deviceId(), String.join(",", scopes))); |
68 | | - token = new StoredToken(resp.obj); |
| 68 | + /*GenericJson resp = session.mercury().sendSync(MercuryRequests.requestToken(session.deviceId(), String.join(",", scopes))); |
| 69 | + token = new StoredToken(resp.obj);*/ |
| 70 | + |
| 71 | + //ToDo: Change MercuryException to NoSuchAlgorithmException when an official fix is available |
| 72 | + try { |
| 73 | + Login5Api api = new Login5Api(session); |
| 74 | + Login5.LoginResponse resp = api.login5( |
| 75 | + Login5.LoginRequest.newBuilder() |
| 76 | + .setStoredCredential(Credentials.StoredCredential.newBuilder() |
| 77 | + .setUsername(session.username()) |
| 78 | + .setData(ByteString.copyFrom(session.apWelcome().getReusableAuthCredentials().toByteArray())) |
| 79 | + .build()) |
| 80 | + .build() |
| 81 | + ); |
| 82 | + if (!resp.hasOk()) throw new IOException("Login5 returned an error: " + resp.getError()); |
| 83 | + Login5.LoginOk okResponse = resp.getOk(); |
| 84 | + |
| 85 | + JsonObject tokenBuilder = new JsonObject(); |
| 86 | + tokenBuilder.addProperty("accessToken", okResponse.getAccessToken()); |
| 87 | + tokenBuilder.addProperty("expiresIn", okResponse.getAccessTokenExpiresIn()); |
| 88 | + tokenBuilder.addProperty("tokenType", "Bearer"); |
| 89 | + |
| 90 | + JsonArray scopesArray = new JsonArray(); |
| 91 | + for (String scope : scopes) |
| 92 | + scopesArray.add(scope); |
| 93 | + |
| 94 | + tokenBuilder.add("scope", scopesArray); |
| 95 | + |
| 96 | + token = new StoredToken(tokenBuilder); |
| 97 | + }catch (NoSuchAlgorithmException e) { |
| 98 | + throw new IOException(e); |
| 99 | + } |
69 | 100 |
|
70 | 101 | ConsoleLoggingModules.debug("Updated token successfully! {scopes: {}, newToken: {}}", Arrays.asList(scopes), token); |
71 | 102 | tokens.add(token); |
|
0 commit comments