Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Jul 27, 2022

Issue #, if available:
closes #16
closes #87

Description of changes:

Adds the ability for authenticated Discord users to link their GitHub account.

New Discord command /login sends user ephemeral message with a url to link their GitHub account. (currently localhost url)

Screen Shot 2022-07-27 at 3 36 02 PM

The GitHub login page can also be reached by clicking the Discord user icon then choosing Link GitHub Account

Screen Shot 2022-07-27 at 3 39 40 PM

  • After linking the GitHub account, in signin event in next-auth generates an app token using a the GitHub App credentials, which is used to ping the GitHub api to check for org members and contributors.

  • Discord staff roles are added to users who are members of the AWS Amplify org, and contributor roles to contributors to the Amplify org. If the user already has a Discord staff or contributor role but does not have these credentials on the Amplify GitHub org, the Discord roles are then removed. Most of this is in src/lib/github/apply-roles

  • Additionally there is a GitHub org webhook that signals org membership changes, in webhooks/github-org-membership. If someone leaves the Amplify org their staff role on Discord will be removed, and if they join the org a staff role will be added.

Testing

  • This change involves the adding about 8 new variables to .env, and instructions for generating these can be found in guide.md (which will need to be integrated into the contribution guide somehow, just here for reference).

  • The Amplify org GitHub App has NOT been installed yet, so some of credentials for this org are still missing. For testing purposes I created a temporary org and GitHub App to test adding staff/contributor roles.

  • If you want to pull this down to test, you can either create your own org and app installation (instructions in guide) or get in touch with me for the for the needed credentials.

login-command.mov

You can see that staff and contributor roles are added to my Discord user after linking my GitHub account.

Screen Shot 2022-07-27 at 3 33 44 PM

Screen Shot 2022-07-27 at 3 34 48 PM

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ghost ghost requested review from josefaidt and dnys1 July 27, 2022 22:57
@lgtm-com
Copy link

lgtm-com bot commented Jul 27, 2022

This pull request introduces 1 alert when merging 4516941 into 1a8f613 - view on LGTM.com

new alerts:

  • 1 for Useless conditional

@ghost ghost added the run-ci Label to trigger action run for CI label Jul 27, 2022
@github-actions github-actions bot removed the run-ci Label to trigger action run for CI label Jul 27, 2022
@ghost ghost added the run-ci Label to trigger action run for CI label Aug 2, 2022
@github-actions github-actions bot removed the run-ci Label to trigger action run for CI label Aug 2, 2022
@ghost ghost temporarily deployed to ci August 2, 2022 23:12 Inactive
@ghost ghost marked this pull request as ready for review August 2, 2022 23:16
@ghost ghost self-requested a review August 2, 2022 23:16
@ghost ghost added the run-ci Label to trigger action run for CI label Aug 2, 2022
@github-actions github-actions bot removed the run-ci Label to trigger action run for CI label Aug 2, 2022
@ghost ghost temporarily deployed to ci August 2, 2022 23:16 Inactive
Co-authored-by: josef <josef.aidt@gmail.com>
Copy link
Contributor

@josefaidt josefaidt left a comment

Choose a reason for hiding this comment

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

Great work on this, Emma! 🚢

@josefaidt josefaidt added the run-ci Label to trigger action run for CI label Aug 2, 2022
@github-actions github-actions bot removed the run-ci Label to trigger action run for CI label Aug 2, 2022
@josefaidt josefaidt temporarily deployed to ci August 2, 2022 23:55 Inactive
Copy link
Contributor

@dnys1 dnys1 left a comment

Choose a reason for hiding this comment

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

LGTM

Couple minor comments, but no need to block on them. Great work! ✨


### Creating the App

1. Go to your GitHub organization, and click **Settings** -> **Developer Settings** -> **GitHub Apps**
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I think in this case we ended up doing a normal App WITH OAuth because we can authenticate the app installation to access organization resources.

if (user.bot) {
return 'This command does not support bots logging in.'
} else return {
content: `${import.meta.env.VITE_HOST}/profile/link`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to send them the OAuth /authorize link?

esauerbo1 and others added 2 commits August 3, 2022 10:11
Co-authored-by: Dillon Nys <24740863+dnys1@users.noreply.github.com>
Co-authored-by: Dillon Nys <24740863+dnys1@users.noreply.github.com>
@lgtm-com
Copy link

lgtm-com bot commented Aug 3, 2022

This pull request introduces 1 alert when merging 620eea6 into e37a293 - view on LGTM.com

new alerts:

  • 1 for Invocation of non-function

@ghost ghost added the run-ci Label to trigger action run for CI label Aug 3, 2022
@github-actions github-actions bot removed the run-ci Label to trigger action run for CI label Aug 3, 2022
@ghost ghost added the run-ci Label to trigger action run for CI label Aug 3, 2022
@github-actions github-actions bot removed the run-ci Label to trigger action run for CI label Aug 3, 2022
@ghost ghost temporarily deployed to ci August 3, 2022 17:23 Inactive
@ghost ghost merged commit 85d13b9 into aws-amplify:main Aug 3, 2022
@ghost ghost deleted the feat/gh-auth branch August 3, 2022 17:28
@ghost ghost restored the feat/gh-auth branch August 5, 2022 23:53
This pull request was closed.
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.

add authentication with GitHub /login -- auto-apply contributor role based on GitHub contributions
3 participants