Skip to content

Commit

Permalink
Fix bearer token issue on requests interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
d-moreira committed Dec 12, 2017
1 parent 78139d7 commit 1f31da2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public class MockRestAdapter<T> {
private UpholdRestAdapter mockRestAdapter;
private RestAdapter restAdapter;

public MockRestAdapter(String token, final String responseString, final HashMap<String, String> headers) {
public MockRestAdapter(final String responseString, final HashMap<String, String> headers) {
this.exceptionReference = new AtomicReference<>();
this.requestReference = new AtomicReference<>();
this.resultReference = new AtomicReference<>();
this.mockRestAdapter = new UpholdRestAdapter();
this.restAdapter = new RestAdapter.Builder().setEndpoint(BuildConfig.API_SERVER_URL)
.setRequestInterceptor(this.mockRestAdapter.getUpholdRequestInterceptor(token))
.setRequestInterceptor(this.mockRestAdapter.getUpholdRequestInterceptor())
.setClient(new Client() {
@Override
public Response execute(Request request) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.uphold.uphold_android_sdk.client.restadapter;

import android.text.TextUtils;

import com.squareup.okhttp.OkHttpClient;
import com.uphold.uphold_android_sdk.BuildConfig;
import com.uphold.uphold_android_sdk.client.errorhandling.UpholdRetrofitErrorHandling;
import com.uphold.uphold_android_sdk.client.session.SessionManager;
import com.uphold.uphold_android_sdk.util.Header;

import android.text.TextUtils;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
Expand Down Expand Up @@ -42,7 +42,7 @@ public UpholdRestAdapter() {
.setClient(new OkClient(okHttpClient))
.setErrorHandler(new UpholdRetrofitErrorHandling())
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
.setRequestInterceptor(getUpholdRequestInterceptor(SessionManager.INSTANCE.getBearerToken()))
.setRequestInterceptor(getUpholdRequestInterceptor())
.build();
}

Expand Down Expand Up @@ -72,16 +72,14 @@ public RestAdapter getAdapter() {
/**
* Gets the {@link RequestInterceptor}.
*
* @param token The token (if available) of the user.
*
* @return the {@link RequestInterceptor}.
*/

public RequestInterceptor getUpholdRequestInterceptor(final String token) {
public RequestInterceptor getUpholdRequestInterceptor() {
return new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
HashMap<String, String> map = Header.getHeaders();
final HashMap<String, String> map = Header.getHeaders();

for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
Expand All @@ -90,7 +88,9 @@ public void intercept(RequestFacade request) {
request.addHeader(key, value);
}

if (token != null && !TextUtils.isEmpty(token)) {
final String token = SessionManager.INSTANCE.getBearerToken();

if (!TextUtils.isEmpty(token)) {
request.addHeader("Authorization", String.format("Bearer %s", token));
}
}
Expand Down

0 comments on commit 1f31da2

Please sign in to comment.