Skip to content

Commit a182ef8

Browse files
committed
Fix deployments and return refresh token
This commit changes the deployments to use the new ossrh staging API. In addition it adds refresh token as an optional return to token request. The token will be set in case PKCE was used.
1 parent bfaf269 commit a182ef8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2677
-155
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
Change Log
22
==========
33

4-
## Version 2.2.1
5-
- Resolve gradle check errors
6-
74
## Version 2.2.0
85
- Requesting token now uses PKCE when:
96
- There is an installed Spotify app that supports PKCE.
107
- When web fallback is used.
8+
- Token requests may return a refresh token if PKCE was used.
119

1210
## Version 2.1.2
1311
* Propagate tracking parameters when opening the native login flow

auth-lib/build.gradle

Lines changed: 3 additions & 4 deletions
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.1'
26+
project.version = '2.2.0'
2727

2828
android {
2929
compileSdk 33
@@ -160,9 +160,8 @@ afterEvaluate {
160160
maven {
161161
getSigningVariables()
162162

163-
def releaseRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
164-
def snapshotRepo = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
165-
url = isReleaseVersion ? releaseRepo : snapshotRepo
163+
name = 'ossrh-staging-api'
164+
url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
166165
credentials {
167166
username = project.ext["ossrhUsername"]
168167
password = project.ext["ossrhPassword"]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
* <p>In both cases, (SSO and browser fallback) the result of the authorization flow will be returned
7676
* in the {@code onActivityResult} method of the activity that initiated it.</p>
7777
*
78-
* <p>
7978
* <pre>{@code
8079
* // Code called from an activity
8180
* private static final int REQUEST_CODE = 1337;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public String toString() {
9090
private final String mState;
9191
private final String mError;
9292
private final int mExpiresIn;
93+
@Nullable
94+
private final String mRefreshToken;
9395

9496
/**
9597
* Use this builder to create an {@link AuthorizationResponse}
@@ -104,6 +106,8 @@ public static class Builder {
104106
private String mState;
105107
private String mError;
106108
private int mExpiresIn;
109+
@Nullable
110+
private String mRefreshToken;
107111

108112
Builder setType(Type type) {
109113
mType = type;
@@ -135,8 +139,13 @@ Builder setExpiresIn(int expiresIn) {
135139
return this;
136140
}
137141

142+
Builder setRefreshToken(@Nullable String refreshToken) {
143+
mRefreshToken = refreshToken;
144+
return this;
145+
}
146+
138147
AuthorizationResponse build() {
139-
return new AuthorizationResponse(mType, mCode, mAccessToken, mState, mError, mExpiresIn);
148+
return new AuthorizationResponse(mType, mCode, mAccessToken, mState, mError, mExpiresIn, mRefreshToken);
140149
}
141150
}
142151

@@ -145,13 +154,15 @@ private AuthorizationResponse(Type type,
145154
String accessToken,
146155
String state,
147156
String error,
148-
int expiresIn) {
157+
int expiresIn,
158+
String refreshToken) {
149159
mType = type != null ? type : Type.UNKNOWN;
150160
mCode = code;
151161
mAccessToken = accessToken;
152162
mState = state;
153163
mError = error;
154164
mExpiresIn = expiresIn;
165+
mRefreshToken = refreshToken;
155166
}
156167

157168
public AuthorizationResponse(@NonNull Parcel source) {
@@ -161,6 +172,7 @@ public AuthorizationResponse(@NonNull Parcel source) {
161172
mAccessToken = source.readString();
162173
mCode = source.readString();
163174
mType = Type.values()[source.readInt()];
175+
mRefreshToken = source.readString();
164176
}
165177

166178
/**
@@ -262,6 +274,11 @@ public int getExpiresIn() {
262274
return mExpiresIn;
263275
}
264276

277+
@Nullable
278+
public String getRefreshToken() {
279+
return mRefreshToken;
280+
}
281+
265282
@Override
266283
public int describeContents() {
267284
return 0;
@@ -275,6 +292,7 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
275292
dest.writeString(mAccessToken);
276293
dest.writeString(mCode);
277294
dest.writeInt(mType.ordinal());
295+
dest.writeString(mRefreshToken);
278296
}
279297

280298
public static final Parcelable.Creator<AuthorizationResponse> CREATOR = new Parcelable.Creator<AuthorizationResponse>() {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ protected void onNewIntent(Intent intent) {
7777
final AuthorizationRequest originalRequest = getRequestFromIntent();
7878
super.onNewIntent(intent);
7979
final Uri responseUri = intent.getData();
80-
80+
8181
// Clear auth-in-progress state to prevent onResume from thinking user canceled
8282
if (responseUri != null) {
8383
mAuthorizationClient.clearAuthInProgress();
8484
}
85-
85+
8686
final AuthorizationResponse response = AuthorizationResponse.fromUri(responseUri);
8787

8888
// Check if this is a CODE response from web fallback that needs token exchange
@@ -91,7 +91,7 @@ protected void onNewIntent(Intent intent) {
9191
if (originalRequest != null &&
9292
originalRequest.getResponseType().equals(TOKEN.toString()) &&
9393
originalRequest.getPkceInformation() != null) {
94-
94+
9595
// Perform PKCE token exchange for web fallback
9696
final AuthorizationResponse.Builder responseBuilder = new AuthorizationResponse.Builder()
9797
.setType(AuthorizationResponse.Type.TOKEN)
@@ -310,6 +310,7 @@ public void run() {
310310
responseBuilder.setType(AuthorizationResponse.Type.TOKEN);
311311
responseBuilder.setAccessToken(tokenResponse.getAccessToken());
312312
responseBuilder.setExpiresIn(tokenResponse.getExpiresIn());
313+
responseBuilder.setRefreshToken(tokenResponse.getRefreshToken());
313314
Log.d(TAG, "PKCE token exchange successful");
314315
} else {
315316
// Convert to ERROR response

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int getSpotifyAppVersionCode(@NonNull Context context, @NonNull Sha1HashU
178178
try {
179179
PackageInfo packageInfo = context.getPackageManager()
180180
.getPackageInfo(packageName, 0);
181-
181+
182182
// Validate signature before returning version info
183183
if (validateSignature(context, packageName, sha1HashUtil)) {
184184
return packageInfo.versionCode;
@@ -195,7 +195,7 @@ static int getSpotifyAppVersionCode(@NonNull Context context, @NonNull Sha1HashU
195195
*
196196
* @param context The context of the caller, used to check package info
197197
* @param minVersionCode Minimum required version code
198-
* @return true if installed version >= minVersionCode, false otherwise
198+
* @return true if installed {@code version >= minVersionCode}, false otherwise
199199
*/
200200
public static boolean isSpotifyVersionAtLeast(@NonNull Context context, int minVersionCode) {
201201
return isSpotifyVersionAtLeast(context, minVersionCode, new Sha1HashUtilImpl());

auth-sample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
android:id="@+id/response_text_view"
6363
android:layout_width="match_parent"
6464
android:layout_height="wrap_content"
65-
android:textSize="10sp"
65+
android:textSize="11sp"
6666
tools:text="Line 1\nLine 2\nLine 3" />
6767

6868
<LinearLayout

auth-sample/src/main/res/values/dimens.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/allclasses-index.html

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html lang="en">
44
<head>
55
<!-- Generated by javadoc -->
6-
<title>All Classes (auth-lib 2.1.2 API)</title>
6+
<title>All Classes (auth-lib 2.2.0 API)</title>
77
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
@@ -20,13 +20,13 @@
2020
<script type="text/javascript"><!--
2121
try {
2222
if (location.href.indexOf('is-external=true') == -1) {
23-
parent.document.title="All Classes (auth-lib 2.1.2 API)";
23+
parent.document.title="All Classes (auth-lib 2.2.0 API)";
2424
}
2525
}
2626
catch(err) {
2727
}
2828
//-->
29-
var data = {"i0":1,"i1":2,"i2":1,"i3":1,"i4":2,"i5":2,"i6":2,"i7":2,"i8":4,"i9":2,"i10":2,"i11":2,"i12":2,"i13":1,"i14":2,"i15":2,"i16":2,"i17":2};
29+
var data = {"i0":1,"i1":2,"i2":1,"i3":1,"i4":2,"i5":2,"i6":2,"i7":2,"i8":4,"i9":2,"i10":2,"i11":2,"i12":2,"i13":1,"i14":2,"i15":2,"i16":2,"i17":2,"i18":2,"i19":2,"i20":2,"i21":2,"i22":2};
3030
var tabs = {65535:["t0","All Classes"],1:["t1","Interface Summary"],2:["t2","Class Summary"],4:["t3","Enum Summary"]};
3131
var altColor = "altColor";
3232
var rowColor = "rowColor";
@@ -191,19 +191,45 @@ <h1 title="All&amp;nbsp;Classes" class="title">All&nbsp;Classes</h1>
191191
</th>
192192
</tr>
193193
<tr id="i15" class="rowColor">
194+
<td class="colFirst"><a href="com/spotify/sdk/android/auth/PKCEInformation.html" title="class in com.spotify.sdk.android.auth">PKCEInformation</a></td>
195+
<th class="colLast" scope="row">&nbsp;</th>
196+
</tr>
197+
<tr id="i16" class="altColor">
198+
<td class="colFirst"><a href="com/spotify/sdk/android/auth/PKCEInformationFactory.html" title="class in com.spotify.sdk.android.auth">PKCEInformationFactory</a></td>
199+
<th class="colLast" scope="row">&nbsp;</th>
200+
</tr>
201+
<tr id="i17" class="rowColor">
194202
<td class="colFirst"><a href="com/spotify/sdk/android/auth/browser/RedirectUriReceiverActivity.html" title="class in com.spotify.sdk.android.auth.browser">RedirectUriReceiverActivity</a></td>
195203
<th class="colLast" scope="row">
196204
<div class="block">Activity that receives the auth response sent by the browser's Custom Tab via deeplink.</div>
197205
</th>
198206
</tr>
199-
<tr id="i16" class="altColor">
207+
<tr id="i18" class="altColor">
200208
<td class="colFirst"><a href="com/spotify/sdk/android/auth/app/SpotifyAuthHandler.html" title="class in com.spotify.sdk.android.auth.app">SpotifyAuthHandler</a></td>
201209
<th class="colLast" scope="row">&nbsp;</th>
202210
</tr>
203-
<tr id="i17" class="rowColor">
211+
<tr id="i19" class="rowColor">
204212
<td class="colFirst"><a href="com/spotify/sdk/android/auth/app/SpotifyNativeAuthUtil.html" title="class in com.spotify.sdk.android.auth.app">SpotifyNativeAuthUtil</a></td>
205213
<th class="colLast" scope="row">&nbsp;</th>
206214
</tr>
215+
<tr id="i20" class="altColor">
216+
<td class="colFirst"><a href="com/spotify/sdk/android/auth/TokenExchangeRequest.html" title="class in com.spotify.sdk.android.auth">TokenExchangeRequest</a></td>
217+
<th class="colLast" scope="row">
218+
<div class="block">A utility class for exchanging an authorization code for an access token using PKCE verifier.</div>
219+
</th>
220+
</tr>
221+
<tr id="i21" class="rowColor">
222+
<td class="colFirst"><a href="com/spotify/sdk/android/auth/TokenExchangeRequest.Builder.html" title="class in com.spotify.sdk.android.auth">TokenExchangeRequest.Builder</a></td>
223+
<th class="colLast" scope="row">
224+
<div class="block">Builder class for creating TokenExchangeRequest instances.</div>
225+
</th>
226+
</tr>
227+
<tr id="i22" class="altColor">
228+
<td class="colFirst"><a href="com/spotify/sdk/android/auth/TokenExchangeResponse.html" title="class in com.spotify.sdk.android.auth">TokenExchangeResponse</a></td>
229+
<th class="colLast" scope="row">
230+
<div class="block">Response from a token exchange request.</div>
231+
</th>
232+
</tr>
207233
</table>
208234
</li>
209235
</ul>

docs/allclasses.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html lang="en">
44
<head>
55
<!-- Generated by javadoc -->
6-
<title>All Classes (auth-lib 2.1.2 API)</title>
6+
<title>All Classes (auth-lib 2.2.0 API)</title>
77
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
88
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
99
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
@@ -35,9 +35,14 @@ <h1 class="bar">All&nbsp;Classes</h1>
3535
<li><a href="com/spotify/sdk/android/auth/FallbackHandlerProvider.html" title="class in com.spotify.sdk.android.auth">FallbackHandlerProvider</a></li>
3636
<li><a href="com/spotify/sdk/android/auth/IntentExtras.html" title="interface in com.spotify.sdk.android.auth"><span class="interfaceName">IntentExtras</span></a></li>
3737
<li><a href="com/spotify/sdk/android/auth/LoginActivity.html" title="class in com.spotify.sdk.android.auth">LoginActivity</a></li>
38+
<li><a href="com/spotify/sdk/android/auth/PKCEInformation.html" title="class in com.spotify.sdk.android.auth">PKCEInformation</a></li>
39+
<li><a href="com/spotify/sdk/android/auth/PKCEInformationFactory.html" title="class in com.spotify.sdk.android.auth">PKCEInformationFactory</a></li>
3840
<li><a href="com/spotify/sdk/android/auth/browser/RedirectUriReceiverActivity.html" title="class in com.spotify.sdk.android.auth.browser">RedirectUriReceiverActivity</a></li>
3941
<li><a href="com/spotify/sdk/android/auth/app/SpotifyAuthHandler.html" title="class in com.spotify.sdk.android.auth.app">SpotifyAuthHandler</a></li>
4042
<li><a href="com/spotify/sdk/android/auth/app/SpotifyNativeAuthUtil.html" title="class in com.spotify.sdk.android.auth.app">SpotifyNativeAuthUtil</a></li>
43+
<li><a href="com/spotify/sdk/android/auth/TokenExchangeRequest.html" title="class in com.spotify.sdk.android.auth">TokenExchangeRequest</a></li>
44+
<li><a href="com/spotify/sdk/android/auth/TokenExchangeRequest.Builder.html" title="class in com.spotify.sdk.android.auth">TokenExchangeRequest.Builder</a></li>
45+
<li><a href="com/spotify/sdk/android/auth/TokenExchangeResponse.html" title="class in com.spotify.sdk.android.auth">TokenExchangeResponse</a></li>
4146
</ul>
4247
</main>
4348
</body>

0 commit comments

Comments
 (0)