-
Notifications
You must be signed in to change notification settings - Fork 89
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
Refactored and fixed device code sample #1
Conversation
consider sharing code between the samples and refactor usernamepwd flow to match what you added for device code... or build one sample that can do both and ask for the user for a key to pick auth method |
Do you mind adding a bit more to the readme file on how to run the samples? |
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.
Added in this commit. |
Added this in this commit. |
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.
Overall looks great. Thank for cleaning up.
Also one more thing that we need to have a full device code implementation:
- A mechanism so that callers can cancel polling. While the polling is happening, the caller should be able to set cancel to true and that would cause the MSAL to break out of the polling loop.
In this new commit, the following changes have been made:
|
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.
Great progress. A couple of questions.
@@ -22,3 +24,9 @@ func (p *AcquireTokenDeviceCodeParameters) augmentAuthenticationParameters(authP | |||
p.commonParameters.augmentAuthenticationParameters(authParams) | |||
authParams.SetAuthorizationType(msalbase.AuthorizationTypeDeviceCode) | |||
} | |||
|
|||
func (p *AcquireTokenDeviceCodeParameters) InternalCallback(dcr *msalbase.DeviceCodeResult) { |
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.
Do we need an internal callback? Can we just call deviceCodeCallback
directly?
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 to cast it to the interface IDeviceCodeResult
. The internal library returns a DeviceCodeResult
, and to make it accessible to the user, we utilize IDeviceCodeResult
.
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.
Can we use the interface in the method signatures internally as well? We should try to use the interface wherever possible.
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.
The interface is not accessible to the internal package. The DeviceCodeRequest uses this callback and passes in a DeviceCodeResult, which this InternalCallback casts to the interface type IDeviceCodeResult.
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.
Can we make the interface accessible to the internal package?
|
||
req.authParameters.SetAuthorityEndpoints(endpoints) | ||
deviceCodeResult, err := req.webRequestManager.GetDeviceCodeResult(req.authParameters) |
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.
Can we update GetDeviceCodeResult to return IDeviceCodeResult? In line 50, req.deviceCodeCallback() can then be updated to be the callback set by the developer, instead of the internal callback?
@@ -22,3 +24,9 @@ func (p *AcquireTokenDeviceCodeParameters) augmentAuthenticationParameters(authP | |||
p.commonParameters.augmentAuthenticationParameters(authParams) | |||
authParams.SetAuthorizationType(msalbase.AuthorizationTypeDeviceCode) | |||
} | |||
|
|||
func (p *AcquireTokenDeviceCodeParameters) InternalCallback(dcr *msalbase.DeviceCodeResult) { |
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.
Can we make the interface accessible to the internal package?
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.
Looks good to me.
src/examples/devicecodeflow/main.go
authorization_pending
andslow_down
errors