-
Notifications
You must be signed in to change notification settings - Fork 229
Third party hosted pub registry authentication #3007
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
- Modified references - Added description about specs is based on RFC7235
login and logout accepts only one argument at most.
Co-authored-by: Jonas Finnemann Jensen <[email protected]>
- Modified messages - Token renamed to Credential
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 think this starts looking good.
LGTM assuming the last comments are addressed
fyi @sigurdm adding limitation to use OAuth credentials only for pub.dev official servers caused some tests to fail (probably because they're using localhost server to test the feature). Should I revert those changes back or what would you suggest? Maybe we could override "official pub server" url using environment variable for the sake of tests. Any suggestions? |
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.
Just a few nits... the part about truncatedMessage
is probably important.
An attacker could otherwise make some very confusing output in the terminal 🙈
} | ||
|
||
final hostedUrl = validateAndNormalizeHostedUrl(json['url'] as String); | ||
final token = json['token'] is String ? json['token'] as String : null; |
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.
Let's throw a FormatException
if token == null
, then we can remove the nullability...
And if we throw FormatException
here, that's fine, because in List<Credential> _loadCredentials() {
we will appropriately log: Failed to load credentials for ${element['url']}:
throw DataException( | ||
'Saved credential for $url pub repository is not supported by current ' | ||
'version of Dart SDK.', | ||
); |
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.
Let's make this a format exception when loading. Then it'll get logged as a warning every time the user uses an old pub version with a newer config file.
Hmm, I can see that being less smart, but I also don't like dragging around nullability.
@sigurdm any thoughts 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.
The issue is current saving mechanism will remove entries that doesn't contains 'token' property because it'll not be able to deserialize it. So they'll not added to the credential list and when saving those entries will be removed.
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 wanted to encapsulate json serialization part to Credential
class itself to reduce code duplication for serialization & validation, otherwise the code would look like much confusing I think.
Yes - I think that is the way to go! (PS When landing: https://github.com/dart-lang/pub/pull/3092this will be more safe, because runningFromTest will no longer only depend on the environment.) |
Yes, used this method - it works. In future when we create integration tests for using token authentication for publishing we might want to declare another environment variable to provide whether given |
Do I have to write integration tests for server integration or we could do that in a separate PR later? |
Thanks @themisir for all the hard work on this! |
Closes #1381
This PR adds support to pub CLI to authenticate with third party hosted pub servers. Before that only official pub servers: pub.dev (aka: pub.dartlang.org) could be authenticated and the authentication was only applied when publishing packages. We usually need to share some pieces of code across company projects. In other ecosystems like npm, nuget, docker this could be done using private repositories / servers. Private repositories does needs authentication for both pulling and pushing data to it - unlike pub's current behavior which only does authenticates requests for pushing new packages.
CLI Interface