-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: main
Are you sure you want to change the base?
Conversation
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. |
Ready for review again |
There was a problem hiding this 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 GameUser
s 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; |
There was a problem hiding this comment.
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
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No sanity check?
/// <param name="visibility">The intended visibility of the object</param> | ||
/// <param name="visibility">The intended visibility of the object</param> |
There was a problem hiding this comment.
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?
/// <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: |
There was a problem hiding this comment.
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?
case Visibility.Game when dataContext.Game != TokenGame.Website: | |
case Visibility.Game when dataContext.Platform != TokenGame.Website: |
/// <param name="visibility">The intended visibility of the object</param> | ||
/// <param name="visibility">The intended visibility of the object</param> |
There was a problem hiding this comment.
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?
/// <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> |
//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) | ||
), |
There was a problem hiding this comment.
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.
public required string? Username { get; set; } | ||
public required string? Name { get; set; } | ||
public required string? ProfileUrl { get; set; } | ||
public required string? AvatarUrl { get; set; } |
There was a problem hiding this comment.
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.
main thing i wanted github auth for was the |
@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 |
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.
RefreshTests.GameServer
folder is just minor refactoring as I fixed some naming when I moved around some code toRefresh.Common
.RefreshTests.GameServer
which refactor manualDataContext
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 toDataContext
, and without this refactor these tests no longer compiled.