Skip to content
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

Support GitHub Apps Installation authentication #70

Merged
merged 52 commits into from
Jun 4, 2024

Conversation

nickfloyd
Copy link
Contributor

@nickfloyd nickfloyd commented May 14, 2024

Description

This PR introduces two things:

  1. A new CLI for the SDK that allows users to authenticate using GitHub Apps Installation tokens. The CLI is a simple command-line tool that allows users to authenticate with GitHub using a GitHub App Installation token or a personal access token. The CLI is designed to be easy to use and can be run from the command line on any platform. It's primary use case is for tight loop development validation and testing.
  2. New classes for app installation and personal access token authentication. These classes are currently used in the CLI for authentication and are for general purpose authenticate with GitHub using GitHub Apps Installation tokens or personal access tokens.

Changes

CLI

  • Added the new CLI project to the solution.
  • Added a new entry point for the CLI that accepts arguments for different authentication methods.
  • Created a new project file for the CLI.
  • Added a README to explain how to use the CLI and set up environment variables for authentication.
  • Added a step to build the main project before the CLI, as the CLI references the main project locally.

Authentication

  • Added new classes for app installation and personal access token authentication.
  • Added new classes to provide authentication for the CLI.

Test coverage has been added to ensure that the new classes and methods are working as expected.

  • Coverage: 83% | Branch coverage: 72%
  • dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=opencover -p:ExcludeByFile="**/GitHub/**/*.cs"

Screenshot 2024-06-04 at 9 45 15 AM

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

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

This is shaping up nicely! FWIW, I don't have strong opinions about the location of the Authentication helpers in the Middleware directory vs. the src root. I'm happy to defer to you, and would probably leave them as-is just for the sake of inertia if you didn't bring it up. Up to you!

@@ -19,6 +19,11 @@ jobs:
with:
dotnet-version: '8.x.x'

# This is a temporary step. Since the CLI references the main project locally, the main
# project must be built first. When the CLI is removed, this may be removed as well.
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to make the CLI a permanent part of this project? If so, this comment can go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think that would be a good move; at least for the short term as we flesh things out.

cli/Program.cs Outdated
}

// Personal Access Token authentication
// var tokenProvider = new TokenProvider(Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? "");
Copy link
Member

Choose a reason for hiding this comment

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

Rather than comments separating multiple types of auth, I'd probably prefer to see separate .cs files for each example like we have on the Go side.

That would also mean we can avoid the ugly serial line commenting like we have below here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good call out... I'll get this cleaned up.

cli/README.md Show resolved Hide resolved
src/GitHub.Octokit.SDK.csproj Outdated Show resolved Hide resolved
/// <summary>
/// This class is responsible for creating, signing and refreshing access tokens
/// </summary>
public class GitHubAppTokenProvider : IGitHubAppTokenProvider
Copy link
Member

Choose a reason for hiding this comment

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

I picked the GitHubAppTokenProvider and IGitHubAppTokenProvider naming here, as it used to be AccessTokenProvider, which I felt clashed with Kiota's IAccessTokenProvider naming/interface, which this does not implement. Please let me know if you have thoughts or better ideas on naming here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just doesn't feel right... perhaps because it's not consistent across all provider naming schemes or it feels redundant with the namespace.

My preference would be to keep it as it was, and just name the interface IGitHubAppTokenProvider or rename them all for consistency (including the test files). Perhaps in the future we'll implement other auth providers? IDK.

I understand the reasoning behind the change, I think my only critique is go all or none with the rename IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I am wondering if we should move Authentication back to a root level folder (like Go), again, for consistency.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed about it not quite feeling right. My main concern with the way it was, was I found it very confusing that our naming scheme matched Kiota's naming scheme for an interface that we didn't implement. Perhaps we can pair on this tomorrow?

I don't have a huge preference on moving Auth code back to the root out of middleware...I'm happy to go either way, and make a decision to potentially revise later.

src/Middleware/Authentication/IGitHubAppTokenProvider.cs Outdated Show resolved Hide resolved
var tokenDescriptorField = _tokenProvider.GetType()
.GetField("_tokenDescriptor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

if (tokenDescriptorField != null)
Copy link
Member

Choose a reason for hiding this comment

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

I mentioned this in the comment above, but I really don't like the reflection here. Please let me know if you have better ideas for testability (using internal instead of private maybe?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think internal should be fine here.. where you thinking about using a decorator to make it available to the test project/file.. i.e.

[assembly: InternalsVisibleTo("test")] or something - I'm good with either way. While not inherently "bad", I'd like to stay away from reflection if possible.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed on staying away from reflection. I'm not sure of the exact incantation required to make the internals testable; if a decorator is the way to go, that's definitely better than reflection. Perhaps we can pair on this tomorrow?

@nickfloyd nickfloyd marked this pull request as ready for review June 4, 2024 14:41
@nickfloyd nickfloyd changed the title Apps token auth delegated middleware Support GitHub Apps Installation authentication Jun 4, 2024
@nickfloyd nickfloyd requested a review from kfcampbell June 4, 2024 17:48
Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

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

This is looking good! I'm excited to see people using this functionality.

@nickfloyd nickfloyd merged commit 6ded6b3 into main Jun 4, 2024
3 checks passed
@nickfloyd nickfloyd deleted the apps-delegated-middleware branch June 4, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants