-
Notifications
You must be signed in to change notification settings - Fork 925
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
feat(rpc): creating scaffolding for JWT authentication #1325
feat(rpc): creating scaffolding for JWT authentication #1325
Conversation
bd277a4
to
382d68a
Compare
5d2b307
to
243a4c1
Compare
Codecov Report
@@ Coverage Diff @@
## main #1325 +/- ##
==========================================
- Coverage 55.33% 55.14% -0.20%
==========================================
Files 180 194 +14
Lines 10962 11800 +838
==========================================
+ Hits 6066 6507 +441
- Misses 4296 4657 +361
- Partials 600 636 +36
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
5d5a84f
to
621c05c
Compare
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.
Very nice description! LGTM.
Requesting changes due to privacy concerns of two API methods.
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 it was hard to understand the problem with reflection. Nice and clever workaround for the given problem! Make it generated and noone will ever read 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.
LGTM. Some of the public could go into read instead, but we can revisit those once we revisit what each module should expose and ADR API compliance
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.
LGTM 🚀
This PR introduces the necessary scaffolding for adding authentication to the OpenRPC server.
This means:
Internal structs
The
API
struct of every module now stores the functions in anInternal
struct. The API structs will now also implement the Module interface, where every method calls the function in it's internal struct. This is ugly, but is necessary in order to use auth with the jsonrpc library for now. We will find a more elegant solution once we have time to implement something custom. The reasoning for this being necessary is complex but I will try to document it a little bit here:API
struct both needs the fields and the implementation that calls the fields, we need to store the fields in anInternal
struct to avoid the naming collision.Auth tags
All methods must have an auth tag on their
API.Internal
field. Right now the available perms areread
,write
, andadmin
. No method can be missing a tag, or it will fail to build.A middleware stub has been added to verify JWTs from the authorization header. This middleware is only used if the header is sent, and otherwise the given permission will default to
read
.Default Implementations
We no longer point to default implementations for docgen. The reason we couldn't do this before was because the API structs did not implement their Module interfaces, so the methods could not be discovered on them through reflection.
P2P
I had to generate the mocks for P2P and add the module in a few places. It wouldn't make much sense to do it in a different PR, but if that is preferred, it should be after this one.
Testing
The rpc tests have been updated to ensure that the API structs implement the full API.
Unit tests also fail if a method does not