Skip to content

Commit 117c8ae

Browse files
Merge pull request #100 from antonholmberg/resolve-gradle-check-errors
Resolve gradle check issues
2 parents c377741 + bfaf269 commit 117c8ae

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Change Log
22
==========
33

4+
## Version 2.2.1
5+
- Resolve gradle check errors
6+
47
## Version 2.2.0
58
- Requesting token now uses PKCE when:
69
- There is an installed Spotify app that supports PKCE.
710
- When web fallback is used.
811

9-
1012
## Version 2.1.2
1113
* Propagate tracking parameters when opening the native login flow
1214

auth-lib/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ apply plugin: 'com.android.library'
2323

2424
project.group = 'com.spotify.android'
2525
project.archivesBaseName = 'auth'
26-
project.version = '2.2.0'
26+
project.version = '2.2.1'
2727

2828
android {
2929
compileSdk 33
@@ -87,6 +87,9 @@ android {
8787
unitTestVariants.configureEach {
8888
it.mergedFlavor.manifestPlaceholders += manifestPlaceholdersForTests
8989
}
90+
testVariants.configureEach {
91+
it.mergedFlavor.manifestPlaceholders += manifestPlaceholdersForTests
92+
}
9093
}
9194

9295
dependencies {

auth-lib/src/main/java/com/spotify/sdk/android/auth/PKCEInformationFactory.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import androidx.annotation.NonNull;
2727

28-
import java.nio.charset.StandardCharsets;
2928
import java.security.MessageDigest;
3029
import java.security.NoSuchAlgorithmException;
3130
import java.security.SecureRandom;
@@ -57,9 +56,14 @@ private static String generateCodeVerifier() {
5756

5857
@NonNull
5958
private static String generateCodeChallenge(@NonNull String codeVerifier) throws NoSuchAlgorithmException {
60-
MessageDigest digest = MessageDigest.getInstance("SHA-256");
61-
byte[] hash = digest.digest(codeVerifier.getBytes(StandardCharsets.US_ASCII));
62-
return Base64.encodeToString(hash, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
59+
try {
60+
MessageDigest digest = MessageDigest.getInstance("SHA-256");
61+
byte[] hash = digest.digest(codeVerifier.getBytes("US-ASCII"));
62+
return Base64.encodeToString(hash, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP);
63+
} catch (final java.io.UnsupportedEncodingException e) {
64+
// US-ASCII is guaranteed to be supported on all platforms
65+
throw new RuntimeException("US-ASCII encoding not supported", e);
66+
}
6367
}
6468
}
6569

auth-lib/src/main/java/com/spotify/sdk/android/auth/TokenExchangeRequest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.net.HttpURLConnection;
3232
import java.net.URL;
3333
import java.net.URLEncoder;
34-
import java.nio.charset.StandardCharsets;
3534

3635
/**
3736
* A utility class for exchanging an authorization code for an access token using PKCE verifier.
@@ -102,7 +101,12 @@ public TokenExchangeResponse execute() {
102101
final String requestBody = buildRequestBody();
103102

104103
try (final OutputStream outputStream = connection.getOutputStream()) {
105-
outputStream.write(requestBody.getBytes(StandardCharsets.UTF_8));
104+
try {
105+
outputStream.write(requestBody.getBytes("UTF-8"));
106+
} catch (final java.io.UnsupportedEncodingException e) {
107+
// UTF-8 is guaranteed to be supported on all platforms
108+
throw new RuntimeException("UTF-8 encoding not supported", e);
109+
}
106110
outputStream.flush();
107111
}
108112

@@ -138,7 +142,7 @@ private String buildRequestBody() {
138142
private String readResponse(@NonNull final HttpURLConnection connection, final boolean isError) throws IOException {
139143
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(
140144
isError ? connection.getErrorStream() : connection.getInputStream(),
141-
StandardCharsets.UTF_8))) {
145+
"UTF-8"))) {
142146

143147
final StringBuilder response = new StringBuilder();
144148
String line;

0 commit comments

Comments
 (0)