Skip to content

Commit d4b4a87

Browse files
committed
Add IOException handling for TOTP secret retrieval
1 parent 6620880 commit d4b4a87

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'de.labystudio'
7-
version '1.3.0'
7+
version '1.3.1'
88

99
compileJava {
1010
sourceCompatibility = '1.8'

src/main/java/de/labystudio/spotifyapi/open/OpenSpotifyAPI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public long requestServerTime() throws IOException {
9898
*/
9999
private AccessTokenResponse generateAccessToken() throws IOException {
100100
Secret secret = this.secretProvider.getSecret();
101+
if (secret == null) {
102+
throw new IOException("No TOTP secret provided");
103+
}
101104

102105
long serverTime = this.requestServerTime();
103106
String totp = TOTP.generateOtp(secret.toBytes(), serverTime, 30, 6);

src/main/java/de/labystudio/spotifyapi/open/totp/provider/SecretProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import de.labystudio.spotifyapi.open.totp.model.Secret;
44

5+
import java.io.IOException;
6+
57
/**
68
* This interface is used to provide a secret for TOTP generation.
79
* It must be implemented to retrieve the latest secret from open.spotify.com
@@ -15,5 +17,5 @@ public interface SecretProvider {
1517
*
1618
* @return The latest TOTP secret used for generating time-based one-time passwords.
1719
*/
18-
Secret getSecret();
20+
Secret getSecret() throws IOException;
1921
}

0 commit comments

Comments
 (0)