Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

Partially implement oauth #69

Closed
wants to merge 29 commits into from

Conversation

robotmayo
Copy link

This PR mostly address #10

This PR lays down the basic foundation for OAUTH support. Right now it doesn't create or do anything with JWTs because there is currently no standard way to create/manipulate JWTs. I thought about adding that but this PR is already quite large so I wanted to cut scope wherever I could. As noted in the a few of the comments there are somethings that we could use such as a standard JSON out and Error response interface. Something like error codes(and types) would also be helpful at simplifying our error responses and make testing a bit better since we would no longer have to check the human readable strings.

Another noted issue is avoiding talking to gorm/database directly and use functions to fetch and write to the database. Another PR is working on something similar (#60). Im also not super great on the tests as its been a while since I have written production level Go advice in this area would be greatly appreciated.

@robotmayo robotmayo requested a review from a team October 29, 2021 22:55
Copy link
Contributor

@RageCage64 RageCage64 left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started! This is one of the trickiest parts of the solution and there isn't much of a codebase to work with yet, so this can't have been a terribly straightforward PR to put together.

I left some "nit" comments, which are mostly pedantic style things, some questions/suggestions, and some small things I'd like to see changed.

handlers/oauth/database.go Outdated Show resolved Hide resolved
if !isNotFoundError {
return nil, result.Error
}
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally if the function did was not successful, it should return some kind of error; returning nil for the error generally implies success. Why do we want to return nil in this case? Maybe there's a compromise that still returns some kind of error here.

Copy link
Author

Choose a reason for hiding this comment

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

Im not entirely sure what our policy should be here. This is technically not an error as not find a user is perfectly expected. I think the only reason gorm errors is because it attempts to update a pointer and theres no easy to say that 'failed'.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say that in this function that we call GetUserByTwitterID, I'd expect to find a user. And since we couldn't find a user with that Twitter ID, you could reasonably throw an error. Maybe we can have a UserNotFoundError which we return in both cases where Gorm errors (i.e. gorm.ErrRecordNotFound) and when a record simply doesn't exist.

handlers/oauth/database.go Show resolved Hide resolved
handlers/oauth/oauth.go Outdated Show resolved Hide resolved
handlers/oauth/oauth.go Show resolved Hide resolved
handlers/oauth/oauth_test.go Outdated Show resolved Hide resolved
handlers/oauth/oauth_test.go Show resolved Hide resolved
handlers/oauth/oauth_test.go Outdated Show resolved Hide resolved
handlers/oauth/oauth_test.go Outdated Show resolved Hide resolved
middleware/jwt.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zysim zysim left a comment

Choose a reason for hiding this comment

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

Looks good, I've just got that one nitpick is all.
EDIT: Ignore me. Looks good to me; just need fixing conflicts and sorting out the other comments 👍

handlers/oauth/oauth_test.go Outdated Show resolved Hide resolved
Sim added 4 commits December 6, 2021 00:56
zysim pushed a commit to zysim/leaderboard-backend-go that referenced this pull request Jun 28, 2022
* Restructured Models, added Models from all PRs

* Add Users integration tests

* Add Integration Test setup

* Add IntegrationTest project
* Include .env in build for integration test project
* Use `Program.cs` as entry point
* Use `Staging` environment for integration tests
* db_test now mounts the correct port on the container
* Adjust env var for test port (test DB will now share name)

* Add Users integration tests

* Add Leaderboard Integration Tests

* Making the tests work with rebases
@robotmayo robotmayo closed this Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants