-
Notifications
You must be signed in to change notification settings - Fork 51
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
Handle API authentication errors for the API services #1034
Handle API authentication errors for the API services #1034
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1034 +/- ##
==========================================
- Coverage 69.36% 69.23% -0.14%
==========================================
Files 275 275
Lines 7152 7193 +41
==========================================
+ Hits 4961 4980 +19
- Misses 2191 2213 +22 ☔ View full report in Codecov by Sentry. |
53e9942
to
c651335
Compare
%{ | ||
errors: %{ | ||
detail: | ||
"Authorization failed due to an invalid path. Ensure the realm name and endpoint are correctly specified in the request" |
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.
Nit: the path does not contain an Astarte endpoint, since this is Realm Management API. See https://docs.astarte-platform.org/astarte/latest/api/?urls.primaryName=Realm%20Management%20API for more
4de7590
to
11d3e7d
Compare
11d3e7d
to
a29db4c
Compare
@@ -130,11 +130,37 @@ defmodule Astarte.RealmManagement.APIWeb.FallbackController do | |||
end | |||
|
|||
# This is called when no JWT token is present | |||
def auth_error(conn, {:unauthenticated, _reason}, _opts) do |
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'll keep a catch-all error handler anyway if there are no other good reasons to remove it.
This goes for all the other services too
a29db4c
to
4e16867
Compare
a7974b2
to
773fd4c
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.
I only looked superficially at the code and it looks good, I'd suggest adding the new errors to the OpenAPI schema of every app (apps/$APP_NAME/priv/static/$APP_NAME.yaml
)
@Annopaolo Since I'm going to change the .yaml files, should I change the contact email as well? |
773fd4c
to
2f7728e
Compare
d8f415f
to
e23c961
Compare
- Expand the Fallback controller with some failed auth functions - Add additional error views with useful feedback messages - Add the gen_jwt_token_with_wrong_signature function in the JWTTestHelper - Add the necessary auth tests and adapt existing ones - Add new errors to the OpenAPI schema Signed-off-by: Armin Ahmetović <[email protected]>
- Expand the Fallback controller with some failed auth functions - Add additional error views with useful feedback messages - Add the gen_jwt_token_with_wrong_signature function in the JWTTestHelper - Add the necessary auth tests and adapt existing ones - Add new errors to the OpenAPI schema Signed-off-by: Armin Ahmetović <[email protected]>
- Expand the Fallback controller with some failed auth functions - Add additional error views with useful feedback messages - Add the gen_jwt_token_with_wrong_signature function in the JWTTestHelper - Add the necessary auth tests and adapt existing ones - Add new errors to the OpenAPI schema Signed-off-by: Armin Ahmetović <[email protected]>
- Expand the Fallback controller with some failed auth functions - Add additional error views with useful feedback messages - Add the gen_jwt_token_with_wrong_signature function in the JWTTestHelper - Add the necessary auth tests and adapt existing ones - Add new errors to the OpenAPI schema Signed-off-by: Armin Ahmetović <[email protected]>
e23c961
to
e7c1eb7
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.
lgtm
Let's change it in another PR! |
What this PR does / why we need it:
fallback_controller
with someauth_error
functionsgen_jwt_token_with_wrong_signature
function in theJWTTestHelper
Which issue(s) this PR fixes:
Fixes: #1031
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g. usage docs, diagrams, etc.:
None