Fix Missing Auth Header + Typo
This commit is contained in:
parent
ff80db973c
commit
0d9002776c
@ -3,6 +3,7 @@ package core.notevault.sync;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import core.notevault.sync.auth.AuthInterceptor;
|
import core.notevault.sync.auth.AuthInterceptor;
|
||||||
|
import core.notevault.sync.auth.TokenManager;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.logging.HttpLoggingInterceptor;
|
import okhttp3.logging.HttpLoggingInterceptor;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -16,9 +17,9 @@ public class ApiClient {
|
|||||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
||||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||||
|
|
||||||
SharedPreferences sharedPreferences = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
|
TokenManager tokenManager = new TokenManager(context);
|
||||||
OkHttpClient client = new OkHttpClient.Builder()
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
.addInterceptor(new AuthInterceptor(sharedPreferences))
|
.addInterceptor(new AuthInterceptor(tokenManager))
|
||||||
.addInterceptor(loggingInterceptor)
|
.addInterceptor(loggingInterceptor)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public class SyncWorker extends Worker{
|
|||||||
Log.d("SyncWorker", "Process SyncResponse");
|
Log.d("SyncWorker", "Process SyncResponse");
|
||||||
//Assign local Concert entries the provided Server ID
|
//Assign local Concert entries the provided Server ID
|
||||||
List<SyncResponse> syncResponses = new ArrayList<>();
|
List<SyncResponse> syncResponses = new ArrayList<>();
|
||||||
for(SyncCreateResponse createResponse : syncResponse.getCreateResonses()) {
|
for(SyncCreateResponse createResponse : syncResponse.getCreateResponses()) {
|
||||||
database.updateConcertServerUUID(createResponse.getServerObjectUUID(), createResponse.getDeviceSpecificObjectID());
|
database.updateConcertServerUUID(createResponse.getServerObjectUUID(), createResponse.getDeviceSpecificObjectID());
|
||||||
syncResponses.add(new SyncResponse(createResponse.getServerObjectUUID(), SyncAction.TOBEUPLOADED, SyncObject.CONCERT));
|
syncResponses.add(new SyncResponse(createResponse.getServerObjectUUID(), SyncAction.TOBEUPLOADED, SyncObject.CONCERT));
|
||||||
}
|
}
|
||||||
|
@ -10,22 +10,17 @@ import okhttp3.Response;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class AuthInterceptor implements Interceptor {
|
public class AuthInterceptor implements Interceptor {
|
||||||
private SharedPreferences sharedPreferences;
|
private TokenManager tokenManager;
|
||||||
|
|
||||||
public AuthInterceptor(SharedPreferences sharedPreferences) {
|
public AuthInterceptor(TokenManager tokenManager) {
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.tokenManager = tokenManager;
|
||||||
String token = sharedPreferences.getString("jwt_token", null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response intercept(Chain chain) throws IOException {
|
public Response intercept(Chain chain) throws IOException {
|
||||||
Request originalRequest = chain.request();
|
Request originalRequest = chain.request();
|
||||||
|
|
||||||
if(originalRequest.url().encodedPath().equals("/api/v1/auth/login")) {
|
String token = tokenManager.getToken();
|
||||||
return chain.proceed(originalRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
String token = sharedPreferences.getString("jwt_token", null);
|
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
return chain.proceed(originalRequest);
|
return chain.proceed(originalRequest);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ public class SyncResponseModel {
|
|||||||
private List<String> toBeUploaded;
|
private List<String> toBeUploaded;
|
||||||
private List<String> toBeDownloaded;
|
private List<String> toBeDownloaded;
|
||||||
private List<String> toBeDeleted;
|
private List<String> toBeDeleted;
|
||||||
private List<SyncCreateResponse> createResonses;
|
private List<SyncCreateResponse> createResponses;
|
||||||
|
|
||||||
public List<String> getToBeUploaded() {
|
public List<String> getToBeUploaded() {
|
||||||
return toBeUploaded;
|
return toBeUploaded;
|
||||||
@ -32,11 +32,11 @@ public class SyncResponseModel {
|
|||||||
this.toBeDeleted = toBeDeleted;
|
this.toBeDeleted = toBeDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SyncCreateResponse> getCreateResonses() {
|
public List<SyncCreateResponse> getCreateResponses() {
|
||||||
return createResonses;
|
return createResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateResonses(List<SyncCreateResponse> createResonses) {
|
public void setCreateResponses(List<SyncCreateResponse> createResponses) {
|
||||||
this.createResonses = createResonses;
|
this.createResponses = createResponses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user