lib: Allow parent scopes when checking if each required scope is set #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
repo
,user:email
andread:org
before this PR), allow parent scopes "instead".repo
is already top-level)user
is the parent scope of, and implies,user:email
. Acceptuser
"instead of"user:email
ifuser:email
isn't narrowly/explicitly found on the token.)admin:org
is the parent scope of, and impliesread:org
. Acceptadmin:org
ifread:org
not explicitly/specifically seen on the token.)public_repo
scope instead of full-onrepo
(but acceptrepo
as its parent scope).Screenshot or Gif
Hint in token entry view when token is missing required scope(s) (click to expand):
Message in Developer Tools console when missing a required scope (click to expand):
Warning in Developer Tools console when excessive scopes are set on the token (click to expand):
Applicable Issues
Mostly fixes pulsar-edit/pulsar#801.
Alternative Approaches
NOTE: I did not update the recommended scopes, since I haven't thoroughly tested what might subtly break if not having full
repo
scope, and this allows just settingpublic_repo
,read:org
anduser:email
. I don't have time to test what a sensible minimum is, and for folks who use private repos, I don't want to have to have a page long explanation of all the intricacies of the different scopes and what they do, especially since the token entry view does not have a scroll bar at the moment!!! Too long of a blurb puts the actual token entry box off of the screen on certain display sizes!!!!!!!!!!!!!!!! (!!!)The warning info in the UI could show the specific missing scope, but that would have to be plumbed into the UI message. That would involve more work to send the info along from the login model and the call site, where we can know what the missing scope is, to the called view, which currently doesn't know that info... It needs to know that info at its render time, in order to renderer the specific scope into the UI.
We could also warn in the UI if a totally invalid token (typo'd, or expired/deleted) is entered, but most of the existing code assumes "maybe it was just a network error" as the same status as "definitely an invalid token" --> either is just "maybe an invalid token". The package doesn't try to distinguish/leaves the situation there, and it acts like you haven't entered anything at all. So, this would take more work than simply plugging in existing bit A to existing bit B, we would have to teach some part of the code to recognize a non-empty token that is wrong even after there was no network error during checking the scopes over the network (it's an API request to the GitHub REST API server). i.e. we need to define a state for when we got a response back from GitHub that the token is actually genuinely (confirmed) invalid.
I kept it relatively simple for this PR. The above is definitely doable, I just wasn't sure if it would be worth it and kind of ran out of steam to do it right here/right now, to be honest.
Misc Notes about scopes
public_repo
is all that seems to be needed from my testing, unless you're working with private repositories.read:org
is needed for working with org-owned repos, but I didn't test this to confirm?user:email
is needed is, TBH, but too afraid to ask (ain't got time to look this up right now, to be honest.