-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor api user check auth0 #84
Conversation
instead of just checking the Auth0 token for the requesting user, we need to permit third party API users to authenticate with an API token. This begins to make those changes
…s by api key instead of Auth0
…f application id is empty
…s to auth with middleware.): Re
…put to include new Api user aut
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.
This looks to be going in the right direction. I think my main comment is to add a method to check if a user isThirdPartyUser
, so that we can track better where this is being called and augment it with additional checks if needed in the future.
src/main/java/org/opentripplanner/middleware/auth/Auth0Connection.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/AbstractUserController.java
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/ApiController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/ApiUserController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/OtpRequestProcessor.java
Outdated
Show resolved
Hide resolved
src/test/java/org/opentripplanner/middleware/ApiUserFlowTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/opentripplanner/middleware/ApiUserFlowTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/opentripplanner/middleware/ApiUserFlowTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/opentripplanner/middleware/ApiUserFlowTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/opentripplanner/middleware/ApiUserFlowTest.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## dev #84 +/- ##
============================================
+ Coverage 46.14% 54.13% +7.98%
- Complexity 363 446 +83
============================================
Files 85 85
Lines 2540 2627 +87
Branches 289 308 +19
============================================
+ Hits 1172 1422 +250
+ Misses 1246 1031 -215
- Partials 122 174 +52
Continue to review full report at Codecov.
|
…after updating the return type
…dress issue with otp user obtai
Nice to see #81 fixed. |
… OTP requests without specifyin
src/main/java/org/opentripplanner/middleware/controllers/api/ApiController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/ApiController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/OtpRequestProcessor.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/models/ApiUser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/OtpUserController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/controllers/api/OtpUserController.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opentripplanner/middleware/models/OtpUser.java
Outdated
Show resolved
Hide resolved
Refactor api user check auth0 ltr
*/ | ||
//FIXME: Move this check into existing auth checks so it would be carried out automatically prior to any | ||
// business logic. Consider edge cases where a user can be both an API user and OTP user. | ||
public static void linkApiKeyToApiUser(Request req) { |
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.
With respect to the method name, maybe just ensureApiUserHasApiKey
? Has this logic changed from its previous iteration? I think, as it stands, this check will cause a halt under the following conditions:
- I sign up as an API user for [email protected]
- I attempt to sign up as an OTP user in the MOD UI using [email protected].
- The halt is thrown because the MOD UI uses a different API key than my API user API key.
Perhaps the way to handle this is with token scopes that we provide in the getCompleteAuth0TokenResponse
method. Let's discuss on our technical call tomorrow.
Javadoc:
Check that the API key used in the incoming request is associated with the matching {@link ApiUser} (which is determined from the Authorization header).
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.
Squirrelly issue with linking API key to user, but perhaps we should address it in a new PR (this one has over 200 comments).
Checklist
dev
before they can be merged tomaster
)Description
This PR builds on #82 by removing all auth based on an Api user's API key. Instead auth is handled by Auth0. To accomodate this, a new endpoint has been added to allow an Api user to obtain a bearer token from Auth0 by providing their username (email) and password.
For clarity, the checks tieing an Otp user to an Api user based on an Api user's API key remains.
PR also includes an update to cover this issue: #81. I could not strictly replicate the issue because Auth0 would reject creating an account with an existing email address. I could replicate if I create the admin user in just otp-middleware. I've added the suggested userId parameter, but if this isn't provided the conditional checks would still allow all trips to be returned for an Otp user. Therefore, I have updated the isUserAdmin to return true only if the requesting user is an admin (i.e. does not have mutiple user types).