Refined-github: Verify token in options

Created on 21 Nov 2020  ·  14Comments  ·  Source: sindresorhus/refined-github

When the user pastes a token, we could verify that the token:

  1. Is active/valid
  2. Has the expected scope(s)

3734 will add a function that helps with this validation.

help wanted meta

Most helpful comment

It's a cache problem, not an API problem

Screen Shot 2020-11-26 at 17 37 11

Use cache: 'no-store'

const {headers} = await fetch('https://api.github.com/', { 
    cache: 'no-store',
    headers: {...}
});

All 14 comments

Did a drop of testing here it does not give back all scopes. For example discussion is not passed back.

We don't need discussion and currently we only soft-require repo and delete_repo, both of which are reported.

Let's take this opportunity to better explain why the token is needed: https://github.com/sindresorhus/refined-github/pull/3757

And then add something like ✅ Valid or ❌ Not set/invalid next to each that is updated with the validation.

From my testing we cannot see if they have public and/or private repo enabled it just returns repo

maxresdefault

public_repo means that they only have access to public repositories.

repo means access to all repositories; this includes public_repo

It's in the notes I added in #3757

Try creating a token with just public_repo and it will show up.

I will try again tomorrow.
I need help understanding how to reset on domain change.

See https://github.com/sindresorhus/refined-github/tree/validate-token for my half baked work.

I just tested and confirmed. It only gives you back what you selected when you created the token. Which means that if you made any changes, the header does not update! It will update if you regenerate the token.

So if a users adds a permission there will be no way for us to update it

@fregante can you confirm too?

That's not right either. You can see the same token changing scopes here, seconds after changing them:

❯ http HEAD https://api.github.com/ "Authorization: token b77a804af914872e62b8c84d009f37f509cf2b58"
HTTP/1.1 200 OK
X-OAuth-Scopes: public_repo

❯ http HEAD https://api.github.com/ "Authorization: token b77a804af914872e62b8c84d009f37f509cf2b58"
HTTP/1.1 200 OK
X-OAuth-Scopes: repo

❯ http HEAD https://api.github.com/ "Authorization: token b77a804af914872e62b8c84d009f37f509cf2b58"
HTTP/1.1 200 OK
X-OAuth-Scopes: delete_repo, public_repo

I think you're confusing "token regeneration" with "token update." The regeneration creates a new token, but that's not what you're supposed to do:

nook

I did both. I will make a screencast. Maybe something was wrong with Github yesterday.

Keep in mind that api.v3 is memoized. Use fetch directly instead

It's a cache problem, not an API problem

Screen Shot 2020-11-26 at 17 37 11

Use cache: 'no-store'

const {headers} = await fetch('https://api.github.com/', { 
    cache: 'no-store',
    headers: {...}
});

THANKS! How did you know I just started wording on it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sindresorhus picture sindresorhus  ·  3Comments

hkdobrev picture hkdobrev  ·  3Comments

fregante picture fregante  ·  3Comments

yakov116 picture yakov116  ·  3Comments

durka picture durka  ·  3Comments