Skip to content

Conversation

SomkaPe
Copy link
Contributor

@SomkaPe SomkaPe commented Feb 19, 2019

Polling implementation of device code flow.
Refactoring of Callable to Supplier.
Use acquireTokenByWindowsIntegratedAuth instead of acquireTokenByKerberosAuth

@@ -1,45 +1,19 @@
// Copyright (c) Microsoft Corporation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Still need a license here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change


return updatedGrant;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

return future;
}


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

CompletableFuture<AuthenticationResult> future =
executorService != null ? CompletableFuture.supplyAsync(supplier, executorService)
: CompletableFuture.supplyAsync(supplier);
futureReference.set(future);
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be due to lack of knowledge around AtomicReferences, but I'm confused as why you need to set this here, since we are returning future and not futureReference.

Copy link
Contributor Author

@SomkaPe SomkaPe Feb 20, 2019

Choose a reason for hiding this comment

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

I have used AtomicReference to make access to future thread safe, same could be done using volatile modifier

import java.security.NoSuchAlgorithmException;

class AcquireTokenCallable extends MsalCallable<AuthenticationResult> {
public class AcquireTokenSupplier extends MsalSupplier {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe AuthenticationResultSupplier instead of MsalSupplier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point will change

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that makes sense? Isn't this kind of a base class for AquireToken ? It's not a base class for AuthenticationResult ?


In reply to: 258718420 [](ancestors = 258718420)

Copy link
Contributor Author

@SomkaPe SomkaPe Feb 21, 2019

Choose a reason for hiding this comment

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

This is a base class for Task which produces(supply) AuthenticationResult

import java.util.concurrent.CompletionException;
import java.util.function.Supplier;

abstract class MsalSupplier implements Supplier<AuthenticationResult> {
Copy link
Contributor

@henrik-me henrik-me Feb 20, 2019

Choose a reason for hiding this comment

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

Supplier [](start = 39, length = 8)

interesting #Resolved

* Token, Refresh Token and the Access Token's expiration time.
*/
public CompletableFuture<AuthenticationResult> acquireTokenByKerberosAuth(Set<String> scopes, String username) {
public CompletableFuture<AuthenticationResult> acquireTokenByWindowsIntegratedAuth(Set<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.

WindowsIntegratedAuth [](start = 65, length = 21)

after a long naming discussion on this previously (analysis by searching google and bing for most used) : IntegratedWindowsAuth was what this landed on. I recommend calling it the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will rename

import java.util.concurrent.Future;
import java.util.function.Consumer;

public class DeviceCodeFlow {
Copy link
Contributor

Choose a reason for hiding this comment

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

DeviceCodeFlow [](start = 13, length = 14)

super easy to understand sample code :)

@henrik-me
Copy link
Contributor

public class IntegratedAuthFlow {

nit: Given the flow name has been updated should the class as well as the filename as well update?


Refers to: src/samples/public-client/IntegratedAuthFlow.java:30 in d8a9f35. [](commit_id = d8a9f35, deletion_comment = False)


import static com.microsoft.aad.msal4j.AdalErrorCode.AUTHORIZATION_PENDING;

public class AcquireTokenDeviceCodeFlowSupplier extends MsalSupplier {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this extend from AquireTokenSupplier? (or based on the naming discussion from AuthenticationResultSupplier) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed AquireTokenSupplier to AcquireTokenByAuthorisationGrantSupplier - which is a bit more precise(get token by auth grant from token endpoint), but AcquireTokenDeviceCodeFlowSupplier is different it is flow

@henrik-me
Copy link
Contributor

It seems like logging was removed? Am I missing something?

Assert.assertNotNull(deviceCode.getExpiresIn(), "900");
Assert.assertNotNull(deviceCode.getInterval(), "5");
Assert.assertNotNull(deviceCode.getMessage(), "To sign in, use a web browser" +
" to open the page https://aka.ms/devicelogin and enter the code DW83JNP2P to authenticate.");
Copy link
Contributor

@henrik-me henrik-me Feb 20, 2019

Choose a reason for hiding this comment

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

what does the second parameter do here? You are asserting for not null, however not sure what that second parameter ads, is that some kind of expected value? If so shouldn't the comparison be made against the expected value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, it is bug - should be assert equal

private ClientAuthentication clientAuth;
private String scopes;
private Consumer<DeviceCode> deviceCodeConsumer;
private AtomicReference<CompletableFuture<AuthenticationResult>> futureReference;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would assume these are all relevant on the base object? Any reason those are defined here and not on the base? Especially scope is something I would expect to be everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is used to support cancellation of long running task - polling of Token and point for device code flow

import java.security.NoSuchAlgorithmException;

class AcquireTokenCallable extends MsalCallable<AuthenticationResult> {
public class AcquireTokenByAuthorisationGrantSupplier extends AuthenticationResultSupplier {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit pick - AcquireTokenByAuthorizationGrantSupplier

PowerMock.replay(app);

AuthenticationResult authResult =
app.acquireTokenDeviceCodeFlow(Collections.singleton(AAD_RESOURCE_ID), deviceCodeConsumer).get();
Copy link
Contributor

Choose a reason for hiding this comment

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

acquireTokenByDeviceCodeFlow similar to acquireTokenByIntegratedWindowsAuth to be consistent with the acquireTokenByxxx format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will rename

Copy link
Contributor

@henrik-me henrik-me left a comment

Choose a reason for hiding this comment

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

:shipit:

@SomkaPe SomkaPe requested a review from navyasric February 26, 2019 02:09
@SomkaPe SomkaPe merged commit 6370d5b into dev Feb 27, 2019
@sangonzal sangonzal deleted the somkape/deviceCodePolling branch April 23, 2019 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants