-
Notifications
You must be signed in to change notification settings - Fork 153
device code flow #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1,45 +1,19 @@ | |||
// Copyright (c) Microsoft Corporation. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will change
|
||
return updatedGrant; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
return future; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra line
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point will change
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 :)
|
||
import static com.microsoft.aad.msal4j.AdalErrorCode.AUTHORIZATION_PENDING; | ||
|
||
public class AcquireTokenDeviceCodeFlowSupplier extends MsalSupplier { |
There was a problem hiding this comment.
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) ?
There was a problem hiding this comment.
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
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."); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polling implementation of device code flow.
Refactoring of Callable to Supplier.
Use acquireTokenByWindowsIntegratedAuth instead of acquireTokenByKerberosAuth