Skip to content

Commit 4a379b6

Browse files
committed
- moves constants in it's usage class
1 parent 2c29deb commit 4a379b6

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

‎src/main/java/com/microsoft/graph/authentication/InternalAuthConstants.java‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎src/main/java/com/microsoft/graph/authentication/TokenCredentialAuthProvider.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
* An implementation of the Authentication Provider with Azure-identity
2323
*/
2424
public class TokenCredentialAuthProvider implements IAuthenticationProvider<Request> {
25+
/** The bearer value for the authorization request header, contains a space */
26+
protected static final String BEARER = "Bearer ";
27+
/** The authorization request header name */
28+
protected static final String AUTHORIZATION_HEADER = "Authorization";
2529

2630
/** TokenCredential expected from user */
2731
private final TokenCredential tokenCredential;
@@ -87,7 +91,7 @@ public void authenticateRequest(@Nonnull final IHttpRequest request) throws Auth
8791
}
8892
final URL requestUrl = request.getRequestUrl();
8993
if(requestUrl != null && ShouldAuthenticateRequest(requestUrl)) {
90-
request.addHeader(InternalAuthConstants.AUTHORIZATION_HEADER, InternalAuthConstants.BEARER + getAccessToken());
94+
request.addHeader(AUTHORIZATION_HEADER, BEARER + getAccessToken());
9195
}
9296
}
9397

@@ -106,7 +110,7 @@ public Request authenticateRequest(@Nonnull final Request request) throws Authen
106110
final HttpUrl requestUrl = request.url();
107111
if(requestUrl != null && ShouldAuthenticateRequest(requestUrl.url())) {
108112
return request.newBuilder()
109-
.addHeader(InternalAuthConstants.AUTHORIZATION_HEADER, InternalAuthConstants.BEARER + getAccessToken())
113+
.addHeader(AUTHORIZATION_HEADER, BEARER + getAccessToken())
110114
.build();
111115
} else {
112116
return request;

‎src/test/java/com/microsoft/graph/authentication/TokenCredentialAuthProviderTest.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public void TokenCredentialAuthProviderTestICoreAuthentication() throws Authenti
4040
final TokenCredentialAuthProvider authProvider = new TokenCredentialAuthProvider(mockCredential);
4141

4242
// Act
43-
Assert.assertNull(request.header(InternalAuthConstants.AUTHORIZATION_HEADER));
43+
Assert.assertNull(request.header(TokenCredentialAuthProvider.AUTHORIZATION_HEADER));
4444
final Request authenticatedRequest = authProvider.authenticateRequest(request);
4545

4646
// Assert
4747
Assert.assertEquals(request.url(), authenticatedRequest.url());
48-
Assert.assertNotNull(authenticatedRequest.header(InternalAuthConstants.AUTHORIZATION_HEADER));
49-
assertEquals(InternalAuthConstants.BEARER + testToken, authenticatedRequest.header(InternalAuthConstants.AUTHORIZATION_HEADER));
48+
Assert.assertNotNull(authenticatedRequest.header(TokenCredentialAuthProvider.AUTHORIZATION_HEADER));
49+
assertEquals(TokenCredentialAuthProvider.BEARER + testToken, authenticatedRequest.header(TokenCredentialAuthProvider.AUTHORIZATION_HEADER));
5050
}
5151
}
5252

@@ -77,8 +77,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
7777
Assert.assertFalse(request.getHeaders().isEmpty());
7878

7979
//Assert
80-
Assert.assertTrue(request.getHeaders().get(0).getName().equals(InternalAuthConstants.AUTHORIZATION_HEADER));
81-
Assert.assertTrue(request.getHeaders().get(0).getValue().equals(InternalAuthConstants.BEARER + this.testToken));
80+
Assert.assertTrue(request.getHeaders().get(0).getName().equals(TokenCredentialAuthProvider.AUTHORIZATION_HEADER));
81+
Assert.assertTrue(request.getHeaders().get(0).getValue().equals(TokenCredentialAuthProvider.BEARER + this.testToken));
8282
}
8383
}
8484
@Test
@@ -90,12 +90,12 @@ public void TokenCredentialAuthProviderDoesNotAddTokenOnInvalidDomainsTestICoreA
9090
final TokenCredentialAuthProvider authProvider = new TokenCredentialAuthProvider(mockCredential);
9191

9292
//Act
93-
Assert.assertNull(request.header(InternalAuthConstants.AUTHORIZATION_HEADER));
93+
Assert.assertNull(request.header(TokenCredentialAuthProvider.AUTHORIZATION_HEADER));
9494
final Request authenticatedRequest = authProvider.authenticateRequest(request);
9595

9696
//Assert
9797
Assert.assertEquals(request.url(), authenticatedRequest.url());
98-
Assert.assertNull(authenticatedRequest.header(InternalAuthConstants.AUTHORIZATION_HEADER));
98+
Assert.assertNull(authenticatedRequest.header(TokenCredentialAuthProvider.AUTHORIZATION_HEADER));
9999
}
100100

101101
@Test

0 commit comments

Comments
 (0)