forked from microsoftgraph/msgraph-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBaseAuthenticationProvider.java
More file actions
30 lines (25 loc) · 1.09 KB
/
Copy pathTestBaseAuthenticationProvider.java
File metadata and controls
30 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.microsoft.graph.functional;
import com.microsoft.graph.authentication.IAuthenticationProvider;
import com.microsoft.graph.http.IHttpRequest;
import com.microsoft.graph.httpcore.ICoreAuthenticationProvider;
import okhttp3.Request;
public class TestBaseAuthenticationProvider implements IAuthenticationProvider, ICoreAuthenticationProvider {
private String _accessToken;
private String hostNameToCheck = "graph";
public TestBaseAuthenticationProvider(String accessToken) {
_accessToken = accessToken;
}
@Override
public Request authenticateRequest(Request request) {
if(request.url().host().toLowerCase().contains(hostNameToCheck))
return request.newBuilder().addHeader("Authorization", "Bearer " + _accessToken).build();
else
return request;
}
@Override
public void authenticateRequest(IHttpRequest request) {
if(request.getRequestUrl().getHost().toLowerCase().contains(hostNameToCheck))
request.addHeader("Authorization",
"Bearer " + _accessToken);
}
}