GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add Authentication Parameter to Web Cmdlets for Basic and OAuth by markekraus · Pull Request #5052 · PowerShell/PowerShell Conversation
|
We could write non-terminating error or just terminating error w/o explicitly Why 'Authorization' ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Mark Kraus (@markekraus) Great work!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| else | ||
| { | ||
| Debug.Assert(false, String.Format("Unrecognized Authorization value: {0}", Authorization)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please use Diagnostics.Assert.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Will fix. Any idea why VS Code gives me this 'Diagnostics' is inaccessible due to its protection level [Microsoft.PowerShell.Commands.Utility]?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Because the 'Diagnostics' is defined in another assembly SDK but we have InternalsVisibleTo in AssemblyInfo.cs - VS Code is still stuped here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining. This is fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| _authorization = value.ToLower(); | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe we should use autoproperty and new public enum type for "Basic","Bearer","OAuth" - 'AuthorizationHeaderEnum' .
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
autoproperty? Please let me know what this is.
As for the new Public Enum. I was following suit with -TransferEncoding which doesn't have a public enum. I'm open to creating one, but I assume this requires committee approval?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I meant https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties
Yes, public API should be approved. I believe it is right place to use it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public virtual SwitchParameter SkipCertificateCheck { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// gets or sets the Token property |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A more detailed description is welcomed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| [Parameter] | ||
| public virtual SwitchParameter AllowUnencryptedAuthorization { get; set; } | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A more detailed description is welcomed.
Please add about correlation with other parameters from PR description.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| It "Verifies Invoke-WebRequest -Authorization <authorization>" -TestCases @( | ||
| @{ authorization = "bearer"} | ||
| @{ authorization = "OAuth"} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Formatting (spaces).
We use it twice - please move to BeforeAll. Below too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I considered that but I wasn't sure if that should be done in this PR or something separate. This PR is adding new features only without altering existing behavior. It's still not clear to me what is too much for one PR and what is not.
I would take that up with IETF. They are the crazy ones that decided that Authorization is the correct term here regardless of what the dictionary begs to differ. 😆 I think '-AllowUnencryptedAuthentication' How about '-AllowUnencryptedSecrets'? Assuming there may be more uses outside of the 'Authorization'. I wouldn't want to have |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Travis CI fail due to #5062 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I believe that the use of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What is the consensus on the parameter names? leave them? change them? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think adding "HeaderType" is more of an impl detail than the average user will care about. And while the header is named Authorization, in articles and papers the overall process is referred to as |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
To be consistent with other cmdlets, I think we should call it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I agree with Steve Lee (@SteveL-MSFT) - really a client do an authentication. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Ok. I have switch Authorization with Authentication, Steve Lee (@SteveL-MSFT) Ilya (@iSazonov) can I get some guidance on the public enum for the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think an enum is good because we rid from many string constants and string comparitions, our code becomes more readable. I only worry about extensibility. Mark Kraus (@markekraus) Please correct the PR header and description (Authentication). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Then we would probably need to include logic that limits the subsets allowed by the authentication parameter. For example, if this enum were used in another cmdlet and it was extended to include |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It's overkill. I mean, this is a public type and users can use it. Although it may be better to mark it as obsolete and document that it is for internal use only. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
c642774 to
98f2201
Compare
|
Ilya (@iSazonov) I guess it is overkill. I looked a how other enums are being implemented for parameter options and have tried to follow their conventions. I chose the name Steve Lee (@SteveL-MSFT) is a comittee review required for the new public enum or is your blessing good enough? Ilya (@iSazonov) and Steve Lee (@SteveL-MSFT) the other outstanding question in this PR is to add a warning to the legacy |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
You can add one commit for the warning :-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mark Kraus (@markekraus) I'll see if I can get a quick committee review on this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| { | ||
| if (Uri.Scheme != "https" && !AllowUnencryptedAuthentication) | ||
| { | ||
| WriteWarning(WebCmdletStrings.UnencryptedCredentialWarning); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe WriteError()? It seems we never use WriteWarning().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yup, this is what ConvertTo-SecureString does if -AsPlainText is used without -Force:
2:8ms> $ss = ConvertTo-SecureString "mypassword" -AsPlainText
ConvertTo-SecureString : The system cannot protect plain text input. To suppress this warning and convert the plain
text to a SecureString, reissue the command specifying the Force parameter. For more information ,type: get-help
ConvertTo-SecureString.
At line:1 char:7
+ $ss = ConvertTo-SecureString "mypassword" -AsPlainText
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], ArgumentException
+ FullyQualifiedErrorId : ImportSecureString_ForceRequired,Microsoft.PowerShell.Commands.ConvertToSecureStringComm
and
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ilya (@iSazonov) I think an error would be a breaking change here. Recall this piece of code is not part of the new -Authentication parameter, but part of the legacy -Credential usage. If we want this an error here, I will revert and that can be done in a separate PR. If we are going to break it, the better way, IMO, is to remove the legacy usage and have it be completely replaced with the new usage and removing the legacy -Credential usage has some cleanup associated with it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It seems the PR is near to merge. I think we shouldn't block it - please revert and open tracking Issue to discuss "warning", "removing" and "force".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe error error with the new -Auth Basic (no -AllowUnen) scenario but not the existing -Credential (no -AllowUnen)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Keith Hill (@rkeithhill) that is already part of this PR 😄 the new method is terminating errors when you tery to use non-HTTPS and can only be suppressed with -AllowUnencryptedAuthentication.
This piece of code that this comment thread is on was just to add some more whining to the legacy -Credential usage which has always casually let you send credentials over HTTP with out so much as a peep.
Ilya (@iSazonov) #5112 for the this. I have reverted that commit (with the exception of the minor spelling fix I the other tests in this PR)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@PowerShell/powershell-committee brief discussion is that adding an enum used as a parameter type doesn't require committee approval, code review feedback is sufficient. The current name and namespace seems appropriate to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Basic: Requires Credential | ||
| /// OAuth/Bearer: Requires Token | ||
| /// </summary> | ||
| [Parameter] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should we assign default WebAuthenticationType.None?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think ther is a need, The enum is never null so its creation here automatically sets it to None since it is the first enum value... at least.. if i understand everything I read correctly. If it wasn't automatically None, all of the many tests would be failing. Unless setting it here provides some kind of emit somewhere. I didin't see any other enum parameters setting a default value.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If internal logic is based on None we should initialize explicitly to None (Can we sort the enum or add new element on first position?). Another way is to being based on Authentication.IsPresent.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Mark Kraus (@markekraus) Thanks for your contribution. I'll allow 24 hours for the code owners to review. Dan Travison (@dantraMSFT) , Paul Higinbotham (@PaulHigin) , & James Truher (@JamesWTruher) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| #region Authorization and Credentials | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you please replace "gets" -> "Gets"?
Although the old comments start with a small letter, the new ones are already capital. In this case, it's better to follow our rules and use the capital letter.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public virtual SwitchParameter SkipCertificateCheck { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// gets or sets the Token property. Token is required by Authentication OAuth and Bearer. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The same "get" -> "Gets".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| <value>Access to the path '{0}' is denied.</value> | ||
| </data> | ||
| <data name="AllowUnencryptedAuthenticationRequired" xml:space="preserve"> | ||
| <value>The cmdlet cannot protect plain text secrets sent over unencrypted connections. To supress this warning and send plain text secrets over unencrypted networks, reissue the command specifying the AllowUnencryptedAuthentication parameter.</value> |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it is more readable to put parameter names in single quotes AllowUnencryptedAuthentication ...
We use the format in other Resx files.
Please edit messages below too.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There is a mix, from what I have seen, of quoted, unquoted and Hyphen prepended in the project. Since there is no clear set standard, I went with the style used for the Web Cmdlets. Please look at the errors in this Resx. I would rather have a separate PR to address the errors styles as whole for these commands than have a few that do not match in this PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I agree. Could you please open a tracking issue (or PR)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I could.. but I think another Issue on standardizing how parameters are displayed in errors within the project is probably warranted first. I'd hate to go through the trouble of changing these error and then have the current way be later selected as the standard (I would hope it's not, because I agree it's not very readable, but its possible). thoughts?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
😄 I've been dragged the PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…rShell#5052) Closes PowerShell#4274 Adds an -Authentication parameter to Invoke-RestMethod and Invoke-WebRequest Adds an -Token parameter to Invoke-RestMethod and Invoke-WebRequest Adds an -AllowUnencryptedAuthentication parameter to Invoke-RestMethod and Invoke-WebRequest Adds tests for various -Authorization uses -Authentication Parameter has 3 options: Basic, OAuth, and Bearer Basic requires -Credential and provides RFC-7617 Basic Authorization credentials to the remote server OAuth and Bearer require the -Token which is a SecureString containing the bearer token to send to the remote server If any authentication is provided for any transport scheme other than HTTPS, the request will result in an error. A user may use the -AllowUnencryptedAuthentication switch to bypass this behavior and send their secrets unencrypted at their own risk. -Authentication does not work with -UseDefaultCredentials and will result in an error. The existing behavior with -Credential is left untouched. When not supplying -Authentication, A user will not receive an error when using -Credential over unencrypted connections. Code design choice is meant to accommodate more Authentication types in the future. Documentation Needed The 3 new parameters will need to be added to the Invoke-RestMethod and Invoke-WebRequest documentation along with examples. Syntax will need to be updated.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.