Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/android/SpotifyOAuthPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.apache.cordova.*;
import org.json.*;

import com.spotify.sdk.android.authentication.*;
import com.spotify.sdk.android.auth.AuthorizationClient;
import com.spotify.sdk.android.auth.AuthorizationRequest;
import com.spotify.sdk.android.auth.AuthorizationResponse;

public class SpotifyOAuthPlugin extends CordovaPlugin {
private static final int LOGIN_REQUEST_CODE = 8139;
Expand All @@ -16,7 +18,7 @@ public class SpotifyOAuthPlugin extends CordovaPlugin {
private CallbackContext currentCtx = null;

@Override
public boolean execute(String action, JSONArray args, CallbackContext ctx)
public boolean execute(String action, JSONArray args, CallbackContext ctx)
throws JSONException {
if ("getCode".equals(action)) {
String clientId = args.getString(0);
Expand All @@ -31,26 +33,26 @@ public boolean execute(String action, JSONArray args, CallbackContext ctx)
}

private void getCode(
final String clientId,
final String redirectUrl,
final String clientId,
final String redirectUrl,
final String[] scopes,
final CallbackContext ctx
) {
cordova.setActivityResultCallback(this);
this.currentCtx = ctx;

AuthenticationRequest ab = (new AuthenticationRequest.Builder(
AuthorizationRequest ab = (new AuthorizationRequest.Builder(
clientId,
AuthenticationResponse.Type.CODE,
AuthorizationResponse.Type.CODE,
redirectUrl
))
.setScopes(scopes)
.setShowDialog(true)
.build();

AuthenticationClient.openLoginActivity(
this.cordova.getActivity(),
LOGIN_REQUEST_CODE,
AuthorizationClient.openLoginActivity(
this.cordova.getActivity(),
LOGIN_REQUEST_CODE,
ab
);
}
Expand All @@ -69,8 +71,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
return;
}

final AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
if (response.getType() == AuthenticationResponse.Type.CODE) {
final AuthorizationResponse response = AuthorizationClient.getResponse(resultCode, intent);
if (response.getType() == AuthorizationResponse.Type.CODE) {
JSONObject res = new JSONObject();
try {
res.put("code", response.getCode());
Expand All @@ -79,7 +81,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
cb.success(res);
} else {
JSONObject err = response.getType() == AuthenticationResponse.Type.EMPTY ?
JSONObject err = response.getType() == AuthorizationResponse.Type.EMPTY ?
this.makeError(
"auth_canceled",
"The user cancelled the authentication process."
Expand All @@ -89,7 +91,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
);
cb.error(err);
}

this.currentCtx = null;
}

Expand All @@ -116,4 +118,4 @@ private static String[] toStringArray(JSONArray arr) {
}
return res;
}
}
}
4 changes: 2 additions & 2 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ repositories {
}

dependencies {
compile 'com.spotify.android:auth:1.0.0-alpha'
implementation 'com.spotify.android:auth:1.2.3'
}

android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
}
1 change: 1 addition & 0 deletions www/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": false,
"skipLibCheck": true,
"experimentalDecorators": true
},
"exclude": [
Expand Down