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

Discord/GitHub account linking #665

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Beyley
Copy link
Member

@Beyley Beyley commented Sep 21, 2024

This PR implements the basic support for Discord/OAuth2 account linking.

This is another doozy of a PR, so I'll break down the changes which you can skip through.

  • Most changes in the RefreshTests.GameServer folder is just minor refactoring as I fixed some naming when I moved around some code to Refresh.Common.
  • There are a couple changes in RefreshTests.GameServer which refactor manual DataContext creation to a helper method which already existed but was just unused for one reason or another. This was spurred on from the fact that more fields were added to DataContext, and without this refactor these tests no longer compiled.

@Beyley Beyley requested a review from jvyden September 21, 2024 06:06
@Beyley
Copy link
Member Author

Beyley commented Sep 21, 2024

while implementing GitHub OAuth integration, i noticed some deficiencies in the current structure of some bits, so I'm going to mark as draft until I resolve those.

@Beyley Beyley marked this pull request as draft September 21, 2024 09:31
@Beyley Beyley changed the title Discord account linking Discord/GitHub account linking Sep 22, 2024
@Beyley Beyley marked this pull request as ready for review September 22, 2024 12:24
@Beyley
Copy link
Member Author

Beyley commented Sep 22, 2024

Ready for review again
I didn't intend to include GitHub account linking in this PR initially, but the GitHub code became intertwined with the cleanup work, and it'd be a lot of work to separate, so I figured I'd include it here, since its fully functional.

Copy link
Member

@jvyden jvyden left a comment

Choose a reason for hiding this comment

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

Okay, there's a lot to unpack here.

I'd like some better documentation for the new database types, OAuthRequest and OAuthTokenRelation since those aren't really explained by their names.

I like the idea of abstraction here, but it seems under-utilized (see how there's many Discord config options around the place, but no GitHub config options in other places)

The idea of people with linked accounts causing requests to be sent every single time their GameUsers are serialized is pretty ridiculous, and it makes me wonder if it's even worth having that on the main response at all. At worst, this should be something we cache, and at best this can be pulled in independently via a different API endpoint (/api/v3/users/uuid/{uuid}/links maybe?). I hardly see a use for pulling in Discord/GitHub information from anywhere but the profile, for example.

Overall, I can see the use for Discord OAuth, but I don't get having a GitHub integration at all. It would be helpful if you explained some use-cases for those so we can track all that.

@@ -7,7 +7,7 @@ namespace Refresh.GameServer.Configuration;
/// </summary>
public class IntegrationConfig : Config
{
public override int CurrentConfigVersion => 6;
public override int CurrentConfigVersion => 9;
Copy link
Member

Choose a reason for hiding this comment

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

No reason to jump this far for a config file

Suggested change
public override int CurrentConfigVersion => 9;
public override int CurrentConfigVersion => 7;

/// <summary>
/// The redirect URL to use for Discord OAuth requests, ex. `https://lbp.littlebigrefresh.com/api/v3/oauth/authenticate`
/// </summary>
public string DiscordOAuthRedirectUrl { get; set; } = "http://localhost:10061/api/v3/oauth/authenticate";
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this be removed in favor of concatenating the endpoint path to ExternalUrl?

/// <summary>
/// The redirect URL to use for GitHub OAuth requests, ex. `https://lbp.littlebigrefresh.com/api/v3/oauth/authenticate`
/// </summary>
public string GitHubOAuthRedirectUrl { get; set; } = "http://localhost:10061/api/v3/oauth/authenticate";
Copy link
Member

Choose a reason for hiding this comment

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

Same here

public OAuthProvider? OAuthGetProviderForRequest(string state)
=> this.OAuthRequests.FirstOrDefault(d => d.State == state)?.Provider;

public GameUser SaveOAuthToken(string state, OAuth2AccessTokenResponse tokenResponse, IDateTimeProvider timeProvider, OAuthProvider provider)
Copy link
Member

Choose a reason for hiding this comment

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

Create or Add sound better here for database function names


public GameUser SaveOAuthToken(string state, OAuth2AccessTokenResponse tokenResponse, IDateTimeProvider timeProvider, OAuthProvider provider)
{
OAuthRequest request = this.OAuthRequests.First(d => d.State == state);
Copy link
Member

Choose a reason for hiding this comment

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

No sanity check?

Comment on lines +37 to +38
/// <param name="visibility">The intended visibility of the object</param>
/// <param name="visibility">The intended visibility of the object</param>
Copy link
Member

Choose a reason for hiding this comment

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

Do you know who else has dementia?

Suggested change
/// <param name="visibility">The intended visibility of the object</param>
/// <param name="visibility">The intended visibility of the object</param>
/// <param name="visibility">The intended visibility of the object</param>


switch (visibility)
{
case Visibility.Game when dataContext.Game != TokenGame.Website:
Copy link
Member

Choose a reason for hiding this comment

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

I think technically we'd want to check for platform?

Suggested change
case Visibility.Game when dataContext.Game != TokenGame.Website:
case Visibility.Game when dataContext.Platform != TokenGame.Website:

Comment on lines +37 to +38
/// <param name="visibility">The intended visibility of the object</param>
/// <param name="visibility">The intended visibility of the object</param>
Copy link
Member

Choose a reason for hiding this comment

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

Do you know who else has dementia?

Suggested change
/// <param name="visibility">The intended visibility of the object</param>
/// <param name="visibility">The intended visibility of the object</param>
/// <param name="visibility">The intended visibility of the object</param>

Comment on lines +61 to +75
//TODO: this data should be cached
DiscordProfileInfo = user.DiscordProfileVisibility.Filter(
user,
dataContext,
ApiDiscordUserResponse.FromOld(dataContext.OAuth
.GetOAuthClient<DiscordOAuthClient>(OAuthProvider.Discord)
?.GetUserInformation(dataContext.Database, dataContext.TimeProvider, user), dataContext)
),
GitHubProfileInfo = user.GitHubProfileVisibility.Filter(
user,
dataContext,
ApiGitHubUserResponse.FromOld(dataContext.OAuth
.GetOAuthClient<GitHubOAuthClient>(OAuthProvider.GitHub)
?.GetUserInformation(dataContext.Database, dataContext.TimeProvider, user), dataContext)
),
Copy link
Member

Choose a reason for hiding this comment

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

Is that making a request every time a user is serialized?

How do I put this...

No.

Comment on lines +9 to +12
public required string? Username { get; set; }
public required string? Name { get; set; }
public required string? ProfileUrl { get; set; }
public required string? AvatarUrl { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Are all of these actually nullable? That doesn't seem right at all.

@Beyley
Copy link
Member Author

Beyley commented Sep 23, 2024

Overall, I can see the use for Discord OAuth, but I don't get having a GitHub integration at all. It would be helpful if you explained some use-cases for those so we can track all that.

main thing i wanted github auth for was the Molecule pin, which is when you get a job at media molecule, i wanted to write some code to bump the github API to get the list of GitHub contributors to the LittleBigRefresh org, and automatically give you this pin if you contribute to any of our projects while having your GH account linked

@jvyden
Copy link
Member

jvyden commented Oct 16, 2024

@Beyley Are you still interested in working on this or do you want me to take this over? Haven't heard anything in a while...

@Beyley
Copy link
Member Author

Beyley commented Oct 16, 2024

@Beyley Are you still interested in working on this or do you want me to take this over? Haven't heard anything in a while...

still interested in working on this, but motivation is all over the place right now, you're free to pick this branch up since idk when i'll have the energy to do so

@jvyden jvyden marked this pull request as draft November 3, 2024 01:53
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.

2 participants