-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#34722] Add Authentication and Authorization to api routes #90
Conversation
->where('uid', $this->id); | ||
}); | ||
})->get(); | ||
} |
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.
Seems like this sort of query should normally be a hasManyThrough
, but given the number of joins this is probably the best way to do it. 👍
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.
Unfortunately the many to many nature of the current schema prevents hasManyThrough
from working and I tried using this package to provide the ability to have that many to many deep relationship as a default eloquent collection. The issue that kept cropping up was that the database tables don't follow Laravel conventions so none of it would play nicely which meant we ended up with a permissions getter method instead.
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.
Oh, neat I hadn't seen that package before. Yeah, not being able to rely on standard naming conventions is tough. But I think you've made it as clean as possible given the legacy table constraints.
public function isVocabularyEditor() | ||
{ | ||
$permissions = $this->getPermissions(); | ||
$vocabEditor = Permission::where('label', 'Edit Vocabulary')->first(); | ||
|
||
return $permissions->contains($vocabEditor); |
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.
So much cleaner! Big improvement.
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.
Nice api auth!
Sticking with Sanctum's pattern and adding a new table for API tokens is probably the right decision. The alternative would be trying to overload the existing legacy api_keys
table, which would complicate things considering how differently they behave.
And given we shouldn't need to use any extra token functionality like abilities
, only authenticate the user, this should handle everything we need from an authentication perspective.
…utes, update axios bootstrapping
9379f48
to
60fc862
Compare
@jglass-st This should be ready for another review. |
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.
Looks good!
Great to have those initial tests. All passing except for the known test_authorized_user_can_update_concept_relationships
exception.
I've added SESSION_DOMAIN
variable to the snac-dev .env
, and I can add it to snac production as well.
Link to Ticket:
https://app.shortcut.com/snac/story/34722/require-user-to-be-an-authenticated-editor-for-any-post-put-delete-actions-on-concept-vocabulary
PR Summary:
Sets up authentication and authorization for api routes. Also adds in
artisan user:add
helper commandTesting Instructions:
ddev artisan test
artisan user:add
can be used to interactively add a user to the systemNotes: