Skip to content

Commit ac9d650

Browse files
committed
Changing iAuthenticationProvider interface to access http request.
1 parent fbbb08e commit ac9d650

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public AuthenticationHandler(IAuthenticationProvider authProvider) {
1717

1818
@Override
1919
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
20-
String token = authProvider.getAccessToken();
21-
request.addHeader("Authorization", "Bearer " + token);
20+
authProvider.authenticateRequest(request);
2221
}
2322

2423
}

src/main/java/com/microsoft/graph/httpcore/IAuthenticationProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import org.apache.http.HttpRequest;
44

55
public interface IAuthenticationProvider {
6-
/**
7-
* Get Access Token
6+
/**
7+
* Authenticates the request
88
*
9+
* @param request the request to authenticate
910
*/
10-
11-
String getAccessToken();
11+
void authenticateRequest(HttpRequest request);
1212
}

src/test/java/com/microsoft/graph/httpcore/AuthenticationHandlerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class AuthenticationHandlerTest {
1717
static String token = "TEST-TOKEN";
1818

1919
public static class AuthProvider implements IAuthenticationProvider{
20-
public String getAccessToken() {
21-
return token;
22-
}
20+
public void authenticateRequest(HttpRequest request) {
21+
request.addHeader("Authorization", "Bearer " + token);
22+
}
2323
}
2424

2525
@Test

src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertTrue;
44

5+
import org.apache.http.HttpRequest;
56
import org.apache.http.impl.client.CloseableHttpClient;
67
import org.junit.Test;
78

@@ -10,10 +11,9 @@ public class HttpClientsTest {
1011
@Test
1112
public void testHttpClientCreation() {
1213
IAuthenticationProvider authprovider = new IAuthenticationProvider() {
13-
@Override
14-
public String getAccessToken() {
15-
return "TOKEN";
16-
}
14+
public void authenticateRequest(HttpRequest request) {
15+
request.addHeader("Authorization", "Bearer " + "TOKEN");
16+
}
1717
};
1818
CloseableHttpClient httpclient = HttpClients.createDefault(authprovider);
1919
assertTrue(httpclient != null);

0 commit comments

Comments
 (0)