Skip to content

Commit 0381ea3

Browse files
committed
Add OAuth as authentication method to Session
1 parent 1b88db9 commit 0381ea3

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import java.util.concurrent.*;
7272
import java.util.concurrent.atomic.AtomicBoolean;
7373

74+
import static xyz.gianlu.librespot.mercury.MercuryRequests.KEYMASTER_CLIENT_ID;
75+
7476
/**
7577
* @author Gianlu
7678
*/
@@ -1001,6 +1003,21 @@ public Builder stored(@NotNull File storedCredentials) throws IOException {
10011003
return this;
10021004
}
10031005

1006+
/**
1007+
* Authenticates via OAuth flow, will prompt to open a link in the browser. This locks until completion.
1008+
*/
1009+
public Builder oauth() throws IOException {
1010+
if (conf.storeCredentials && conf.storedCredentialsFile.exists())
1011+
return stored();
1012+
1013+
try (OAuth oauth = new OAuth(KEYMASTER_CLIENT_ID, "http://127.0.0.1:5588/login")) {
1014+
loginCredentials = oauth.flow();
1015+
} catch (InterruptedException ignored) {
1016+
}
1017+
1018+
return this;
1019+
}
1020+
10041021
/**
10051022
* Authenticates with your Facebook account, will prompt to open a link in the browser. This locks until completion.
10061023
*/
@@ -1034,8 +1051,11 @@ public Builder blob(@NotNull String username, byte[] blob) throws GeneralSecurit
10341051
*
10351052
* @param username Your Spotify username
10361053
* @param password Your Spotify password
1054+
*
1055+
* @deprecated Use OAuth instead
10371056
*/
10381057
@NotNull
1058+
@Deprecated
10391059
public Builder userPass(@NotNull String username, @NotNull String password) {
10401060
loginCredentials = Authentication.LoginCredentials.newBuilder()
10411061
.setUsername(username)

0 commit comments

Comments
 (0)