Skip to content

Add GitHub authentication#874

Merged
shati-patel merged 8 commits intogithub:qc-developmentfrom
shati-patel:shati-patel/auth
Jun 9, 2021
Merged

Add GitHub authentication#874
shati-patel merged 8 commits intogithub:qc-developmentfrom
shati-patel:shati-patel/auth

Conversation

@shati-patel
Copy link
Copy Markdown
Contributor

@shati-patel shati-patel commented Jun 4, 2021

Adds a command to authenticate to GitHub. This doesn't do anything yet, but will be helpful in future so we can use the GitHub API. When you run the command CodeQL: Authenticate to GitHub, you should get a prompt to log in. If you're already logged in, a pop up shows the user you're authenticated as.

The main changes here are authentication.ts and extension.ts (mostly based on this VS Code sample). I had to update to VS Code 1.48.0 to use the authentication API, so there are lots of unrelated changes to make existing code compatible with updated packages.

Tests are currently broken, presumably because we need to properly implement the MockExtensionContext test class. EDIT: This was actually due to an outdated version of eslint.

Checklist

TODO

I'm not sure we want to merge this yet, or wait until we have a use for this authentication 🤔 Merged into a separate development branch instead, so this won't be live for a while.

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • @github/docs-content-codeql has been cc'd in all issues for UI or other user-facing changes made by this pull request.

Adds a command to authenticate to GitHub. This doesn't do anything yet, but will be helpful in future so we can use the GitHub API.
I had to update to VS Code 1.48.0 to use the authentication API, so there are some unrelated changes to make existing code compatible.
Fixes the parsing errors: `Cannot read property 'map' of undefined`
(+ disabled a few rules that aren't important)
@shati-patel shati-patel marked this pull request as ready for review June 7, 2021 17:52
(since we've disabled the "ban Function type" linting check in test files)
Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible. A few comments.

Copy link
Copy Markdown
Contributor

@robertbrignull robertbrignull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought I'd have a read through of this too, so I can learn a bit about how the vscode extension works too.


async initialize(context: vscode.ExtensionContext): Promise<void> {
this.registerListeners(context);
this.setOctokit();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs an await.

You may find it useful to add the "@typescript-eslint/no-floating-promises": "error" linting rule, though I tried it and there are a lot of cases caused by async logging calls, so probably not something to look at in this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. We can use the ignoreVoid: true flag to allow the explicit ignoring of promises. It's a bit of a change to make the switchover, but probably worth it. I'll look at it later today.

@shati-patel shati-patel marked this pull request as draft June 8, 2021 11:48
@shati-patel shati-patel marked this pull request as ready for review June 8, 2021 14:56
Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some stylistic comments that you can take or leave.

Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on line 24 is important, and the one on 32 isn't.

@shati-patel shati-patel removed the request for review from adityasharad June 9, 2021 10:30
@aeisenberg
Copy link
Copy Markdown
Contributor

Trying this out locally. And I realize you need to add the codeQL.authenticateToGitHub command to activation activationEvents. This will ensure that the extension is loaded if someone tries to run this command.

@aeisenberg
Copy link
Copy Markdown
Contributor

And, is there a way to log out once you log in? There doesn't need to be a command for this, but I would like to be able to test different workflows and make sure that there's no way to break things.

@shati-patel
Copy link
Copy Markdown
Contributor Author

And, is there a way to log out once you log in? There doesn't need to be a command for this, but I would like to be able to test different workflows and make sure that there's no way to break things.

I've been using the "Accounts" menu in the sidebar to manage access or sign out:

image

@aeisenberg
Copy link
Copy Markdown
Contributor

Thanks...

Here's an error path. I'm not sure if there's much you can do about it since the auth flow is a bit error prone in some ways anyway:

  1. Run the codeQL.authenticateToGitHub command
  2. Click Allow
  3. Navigate to the browser
  4. Click Do not authorize

Now, you are not authorized and repeatedly trying to run the authorize command does not work.

Again, this might be a bug in the vscode API, but something to explore.

@shati-patel
Copy link
Copy Markdown
Contributor Author

Here's an error path. I'm not sure if there's much you can do about it since the auth flow is a bit error prone in some ways anyway:

  1. Run the codeQL.authenticateToGitHub command
  2. Click Allow
  3. Navigate to the browser
  4. Click Do not authorize

Now, you are not authorized and repeatedly trying to run the authorize command does not work.

Hmm yes, that is annoying... I've seen the same behaviour with other extensions (for example when signing into Live Share), but it's not ideal in any case 🤔

I've found a few ways to get out of the non-authorized state (e.g. by clicking "Signing into GitHub..." in the notification bar at the bottom of VS Code, or clicking "Accounts > Sign in to use CodeQL" from the sidebar. So it's probably OK for now, but we might want to add some kind of warning/notification for users when this is eventually ready to go live.

@shati-patel shati-patel changed the base branch from main to qc-development June 9, 2021 18:53
@shati-patel
Copy link
Copy Markdown
Contributor Author

(PS: Targetting this PR against a new development branch, since we don't want to merge to main yet.)

Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. The remaining auto workflow bugs are outside the scope of this extension.

@shati-patel shati-patel merged commit 6db19b2 into github:qc-development Jun 9, 2021
@shati-patel shati-patel deleted the shati-patel/auth branch June 9, 2021 19:05
shati-patel added a commit that referenced this pull request Jun 14, 2021
@shati-patel shati-patel mentioned this pull request Jun 14, 2021
4 tasks
shati-patel added a commit that referenced this pull request Jun 14, 2021
shati-patel added a commit that referenced this pull request Jun 14, 2021
shati-patel added a commit that referenced this pull request Jun 15, 2021
shati-patel added a commit to shati-patel/vscode-codeql that referenced this pull request Jun 22, 2021
shati-patel added a commit that referenced this pull request Jun 23, 2021
Two new "canary" commands:
* GitHub authentication (from #874)
* Workflow dispatch (run remote query)
aofaof0907 pushed a commit to aofaof0907/vscode-codeql that referenced this pull request Jul 27, 2021
Two new "canary" commands:
* GitHub authentication (from github#874)
* Workflow dispatch (run remote query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants