Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,18 @@ protected static void validateNotNull(String name, Object obj) {
* Acquires security token from the authority using an authorization code
* previously received.
*
* @param scopes scopes of the access request
* @param authorizationCode The authorization code received from service authorization endpoint.
* @param redirectUri (also known as Reply URI or Reply URL),
* is the URI at which Azure AD will contact back the application with the tokens.
* This redirect URI needs to be registered in the app registration portal.
* @param scopes scopes of the access request
* @return A {@link Future} object representing the
* {@link AuthenticationResult} of the call. It contains Access
* Token, Refresh Token and the Access Token's expiration time.
*/
public CompletableFuture<AuthenticationResult> acquireTokenByAuthorizationCode(String authorizationCode,
URI redirectUri, String scopes)
public CompletableFuture<AuthenticationResult> acquireTokenByAuthorizationCode(String scopes,
String authorizationCode,
URI redirectUri)
{
validateNotBlank("authorizationCode", authorizationCode);
validateNotBlank("redirectUri", authorizationCode);
Expand All @@ -181,23 +182,6 @@ public CompletableFuture<AuthenticationResult> acquireTokenByAuthorizationCode(S
return this.acquireToken(authGrant, clientAuthentication);
}

/**
* Acquires security token from the authority using an authorization code
* previously received.
*
* @param authorizationCode The authorization code received from service authorization endpoint.
* @param redirectUri (also known as Reply URI or Reply URL),
* is the URI at which Azure AD will contact back the application with the tokens.
* This redirect URI needs to be registered in the app registration portal.
* @return A {@link CompletableFuture} object representing the
* {@link AuthenticationResult} of the call. It contains Access
* Token, Refresh Token and the Access Token's expiration time.
*/
public CompletableFuture<AuthenticationResult> acquireTokenByAuthorizationCode(String authorizationCode, URI redirectUri)
{
return acquireTokenByAuthorizationCode(authorizationCode, redirectUri, null);
}

/**
* Acquires a security token from the authority using a Refresh Token
* previously received.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private ClientAuthentication createClientAuthFromClientAssertion(
* Token and the Access Token's expiration time. Refresh Token
* property will be null for this overload.
*/
public CompletableFuture<AuthenticationResult> acquireToken(final String scopes) {
public CompletableFuture<AuthenticationResult> acquireTokenForClient(String scopes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acquireTokenForClient seems a bit redundant. Is there a reason why we want to swtich from acquireToken to acquireTokenForClient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be consistent with .NET naming

validateNotBlank("scopes", scopes);

MsalOAuthAuthorizationGrant authGrant = new MsalOAuthAuthorizationGrant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void initClientAuthentication(String clientId){
* {@link AuthenticationResult} of the call. It contains Access
* Token, Refresh Token and the Access Token's expiration time.
*/
public CompletableFuture<AuthenticationResult> acquireToken(String scopes, String username, String password) {
public CompletableFuture<AuthenticationResult> acquireTokenByUsernamePassword(String scopes, String username, String password) {
validateNotBlank("scopes", scopes);
validateNotBlank("username", username);

Expand All @@ -83,7 +83,7 @@ public CompletableFuture<AuthenticationResult> acquireToken(String scopes, Strin
* {@link AuthenticationResult} of the call. It contains Access
* Token, Refresh Token and the Access Token's expiration time.
*/
public CompletableFuture<AuthenticationResult> acquireToken(String scopes, String username) {
public CompletableFuture<AuthenticationResult> acquireTokenByKerberosAuth(String scopes, String username) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yKerberosAuth [](start = 64, length = 13)

Isn't this called IntegratedWindowsAuth in the .NET SDK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but these cased are different , Kerberos is platform agnostic

validateNotBlank("scopes", scopes);
validateNotBlank("username", username);

Expand Down
2 changes: 1 addition & 1 deletion src/samples/public-client/IntegratedAuthFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static AuthenticationResult getAccessTokenByIntegratedAuth() throws Exce
.build();

Future<AuthenticationResult> futureAuthenticationResult =
app.acquireToken(TestData.GRAPH_DEFAULT_SCOPE, TestData.USER_NAME);
app.acquireTokenByKerberosAuth(TestData.GRAPH_DEFAULT_SCOPE, TestData.USER_NAME);

AuthenticationResult result = futureAuthenticationResult.get();

Expand Down
2 changes: 1 addition & 1 deletion src/samples/public-client/RTFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static AuthenticationResult getAccessTokenFromUserCredentials()
.authority(TestData.AUTHORITY)
.build();

Future<AuthenticationResult> future = app.acquireToken
Future<AuthenticationResult> future = app.acquireTokenByUsernamePassword
(TestData.GRAPH_DEFAULT_SCOPE, TestData.USER_NAME, TestData.USER_PASSWORD);
AuthenticationResult result = future.get();

Expand Down
2 changes: 1 addition & 1 deletion src/samples/public-client/UsernamePasswordFlowAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static void getAccessTokenFromUserCredentials() throws Exception {
.authority(TestData.AUTHORITY)
.build();

CompletableFuture<AuthenticationResult> future = app.acquireToken
CompletableFuture<AuthenticationResult> future = app.acquireTokenByUsernamePassword
(TestData.GRAPH_DEFAULT_SCOPE, TestData.USER_NAME, TestData.USER_PASSWORD);

future.handle((res, ex) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private AuthenticationResult getAccessTokenByAuthCode(
ConfidentialClientApplication app = createClientApplication();

Future<AuthenticationResult> future = app
.acquireTokenByAuthorizationCode(authCode, new URI(currentUri), null);
.acquireTokenByAuthorizationCode(null, authCode, new URI(currentUri));

result = future.get();
} catch (ExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockTestCase;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import javax.net.ssl.SSLSocketFactory;
import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URI;
import java.security.KeyStore;
import java.security.MessageDigest;
Expand All @@ -46,10 +41,6 @@
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import static org.testng.Assert.*;
Expand Down Expand Up @@ -80,8 +71,8 @@ public void testAcquireTokenAuthCode_ClientCredential() throws Exception {
false));
PowerMock.replay(app);
Future<AuthenticationResult> result = app
.acquireTokenByAuthorizationCode("auth_code", new URI(
TestConfiguration.AAD_DEFAULT_REDIRECT_URI), null);
.acquireTokenByAuthorizationCode(null, "auth_code",
new URI(TestConfiguration.AAD_DEFAULT_REDIRECT_URI));
AuthenticationResult ar = result.get();
Assert.assertNotNull(ar);
PowerMock.verifyAll();
Expand Down Expand Up @@ -118,9 +109,8 @@ public void testAcquireTokenAuthCode_KeyCredential() throws Exception {

PowerMock.replay(app);
Future<AuthenticationResult> result = app
.acquireTokenByAuthorizationCode("auth_code", new URI(
TestConfiguration.AAD_DEFAULT_REDIRECT_URI),
null);
.acquireTokenByAuthorizationCode(null, "auth_code",
new URI(TestConfiguration.AAD_DEFAULT_REDIRECT_URI));
AuthenticationResult ar = result.get();
Assert.assertNotNull(ar);
PowerMock.verifyAll();
Expand Down Expand Up @@ -155,7 +145,7 @@ public void testAcquireToken_KeyCred() throws Exception {
new Date().getTime(), null, null, false));

PowerMock.replay(app);
final Future<AuthenticationResult> result = app.acquireToken(
final Future<AuthenticationResult> result = app.acquireTokenForClient(
TestConfiguration.AAD_RESOURCE_ID);
final AuthenticationResult ar = result.get();
assertNotNull(ar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.nimbusds.jose.JOSEException;
Expand All @@ -63,7 +61,6 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockTestCase;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -259,7 +256,7 @@ public void oAuthRequest_for_acquireTokenByClientAssertion() throws Exception {
.build();

// Using ClientAssertion for Client Authentication and as the authorization grant
Future<AuthenticationResult> future = app.acquireToken(SCOPES);
Future<AuthenticationResult> future = app.acquireTokenForClient(SCOPES);

future.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@
import static org.testng.Assert.assertTrue;

import javax.net.ssl.SSLSocketFactory;
import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URI;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.nimbusds.oauth2.sdk.auth.ClientAuthentication;
Expand All @@ -52,8 +43,6 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockTestCase;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

@PowerMockIgnore({"javax.net.ssl.*"})
Expand Down Expand Up @@ -93,7 +82,7 @@ public void testAcquireToken_Username_Password() throws Exception {

PowerMock.replay(app, response, UserDiscoveryRequest.class);
Future<AuthenticationResult> result =
app.acquireToken("scopes", "username", "password");
app.acquireTokenByUsernamePassword("scopes", "username", "password");

AuthenticationResult ar = result.get();
Assert.assertNotNull(ar);
Expand Down