This repository was archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auth routes to authentication servlet to communicate with Dex (#490)
* Add /auth and /auth/callback GET requests to OpenAPI docs Signed-off-by: Eamonn Mansour <[email protected]> * Bump api.common and authentication bundles to 0.31.0 Signed-off-by: Eamonn Mansour <[email protected]> * Allow root routes to match without trailing / and update mock servlet implementations Signed-off-by: Eamonn Mansour <[email protected]> * Add GET method for /auth, change auth servlet to use routes Signed-off-by: Eamonn Mansour <[email protected]> * Add /auth/callback route and unit tests Signed-off-by: Eamonn Mansour <[email protected]> * Add auto-generated Dex gRPC client Signed-off-by: Eamonn Mansour <[email protected]> * Add gRPC client and DTO Signed-off-by: Eamonn Mansour <[email protected]> * Add POST /auth/clients route Signed-off-by: Eamonn Mansour <[email protected]> * Store state param in session, add callback URL to redirect on auth completion, other tweaks Signed-off-by: Eamonn Mansour <[email protected]> * Update openapi.yaml Signed-off-by: Eamonn Mansour <[email protected]> * Add /auth/clients to OpenAPI docs, preserve query parameters in the callback URL provided by the user Signed-off-by: Eamonn Mansour <[email protected]> * Reuse Dex gRPC stub Signed-off-by: Eamonn Mansour <[email protected]> * Download Dex gRPC .proto file in gradle build Signed-off-by: Eamonn Mansour <[email protected]> * Add more error handling when getting OIDC config Signed-off-by: Eamonn Mansour <[email protected]> * Add logging and don't follow redirect when getting redirect URL Signed-off-by: Eamonn Mansour <[email protected]> * Add external API server URL as an env variable to get auth callback URL Signed-off-by: Eamonn Mansour <[email protected]> * Move callback route URL retrieval into auth callback route Signed-off-by: Eamonn Mansour <[email protected]> * Use consistent casing in auth responses Signed-off-by: Eamonn Mansour <[email protected]> * Bump GSON to 2.10.1 Signed-off-by: Eamonn Mansour <[email protected]> * Remove extra logging and general tidy-up Signed-off-by: Eamonn Mansour <[email protected]> * Add unit tests for Dex gRPC client class Signed-off-by: Eamonn Mansour <[email protected]> * Refactor the initialisation of the oidcProvider and dexGrpcClient fields in the auth servlet Signed-off-by: Eamonn Mansour <[email protected]> * Add example errors to openapi.yaml Signed-off-by: Eamonn Mansour <[email protected]> * Fix formatting Signed-off-by: Eamonn Mansour <[email protected]> * Move env variable names into separate class, bump gson to 2.10.1 Signed-off-by: Eamonn Mansour <[email protected]> * Add sequence diagrams for various auth flows Signed-off-by: Eamonn Mansour <[email protected]> * Add more logging, use single returns in methods where possible Signed-off-by: Eamonn Mansour <[email protected]> * Resolve review comments Signed-off-by: Eamonn Mansour <[email protected]> * Empty commit to kick off build Signed-off-by: Eamonn Mansour <[email protected]> --------- Signed-off-by: Eamonn Mansour <[email protected]>
- Loading branch information
Showing
39 changed files
with
2,838 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ docs/generated/ | |
|
||
# A folder scripts can put things into without fear of them being checked-in. | ||
temp/ | ||
*.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@startuml cli-auth-refresh | ||
title "Authentication flow to get a new JWT for the Galasa CLI tool using a refresh token" | ||
|
||
actor User | ||
participant GalasaCLI as "Galasa CLI" | ||
participant AuthAPI as "Auth API" | ||
participant Dex | ||
|
||
User -> GalasaCLI: Runs "galasactl auth login" | ||
activate GalasaCLI | ||
|
||
GalasaCLI -> AuthAPI: POST /auth (client_id, client_secret, refresh_token) | ||
activate AuthAPI | ||
|
||
AuthAPI -> Dex: POST /token (client_id, client_secret, refresh_token) | ||
activate Dex | ||
Dex --> AuthAPI: Success response (JWT, refresh token) | ||
deactivate Dex | ||
AuthAPI --> GalasaCLI: Success response (JWT, refresh token) | ||
deactivate AuthAPI | ||
|
||
GalasaCLI --> User: Stores the JWT in GALASA_HOME/bearer-token.json | ||
deactivate GalasaCLI | ||
@enduml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@startuml initial-auth-flow | ||
title "Authentication flow when logging in to the Galasa Ecosystem for the first time" | ||
|
||
actor User | ||
participant WebUI as "Web UI" | ||
participant AuthAPI as "Auth API" | ||
participant Dex | ||
|
||
User -> WebUI: Navigates to the web UI | ||
activate WebUI | ||
|
||
WebUI -> AuthAPI: GET /auth?client_id=galasa-webui&callback_url=http://webui-hostname/callback | ||
activate AuthAPI | ||
note left | ||
This GET /auth request uses the | ||
static client ID for the web UI | ||
that was configured into Dex. | ||
end note | ||
|
||
AuthAPI -> Dex: GET /auth?client_id=galasa-webui&scope=...&state=somestate&redirect_uri=http://galasa-api/auth/callback | ||
activate Dex | ||
Dex --> AuthAPI: Redirect to /auth/callback?code=someauthcode&state=somestate | ||
deactivate Dex | ||
AuthAPI --> WebUI: Redirect to http://webui-hostname/callback?code=someauthcode | ||
deactivate AuthAPI | ||
note left | ||
The redirect's location is the | ||
same "callback_url" provided in | ||
the initial GET /auth request. | ||
end note | ||
|
||
WebUI -> AuthAPI: POST /auth (client_id, client_secret, code) | ||
activate AuthAPI | ||
AuthAPI -> Dex: POST /token (client_id, client_secret, code) | ||
activate Dex | ||
Dex --> AuthAPI: Success response (JWT, refresh token) | ||
deactivate Dex | ||
AuthAPI --> WebUI: Success response (JWT, refresh token) | ||
deactivate AuthAPI | ||
|
||
WebUI --> User: Displays the web UI's landing page | ||
deactivate WebUI | ||
@enduml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions
54
docs/images/authentication/personal-access-token-flow.plantuml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@startuml personal-access-token-flow | ||
title "Authentication flow when requesting a new personal access token" | ||
|
||
actor User | ||
participant WebUI as "Web UI" | ||
participant AuthAPI as "Auth API" | ||
participant Dex | ||
|
||
User -> WebUI: Requests personal access token | ||
activate WebUI | ||
|
||
WebUI -> AuthAPI: POST /auth/clients with "Authorization: Bearer <JWT>" header | ||
activate AuthAPI | ||
AuthAPI -> AuthAPI: Check "Authorization" header contains a valid JWT | ||
AuthAPI -> Dex: gRPC call to createClient() | ||
activate Dex | ||
Dex --> AuthAPI: Success response (client_id, client_secret) | ||
deactivate Dex | ||
AuthAPI --> WebUI: Success response (client_id, client_secret) | ||
deactivate AuthAPI | ||
|
||
WebUI -> AuthAPI: GET /auth?client_id=myclient&callback_url=http://webui-hostname/callback | ||
activate AuthAPI | ||
note left | ||
The following is identical to the | ||
initial authentication flow, but | ||
the client_id used will be the ID | ||
of the newly created Dex client. | ||
end note | ||
|
||
AuthAPI -> Dex: GET /auth?client_id=myclient&scope=...&state=somestate&redirect_uri=http://galasa-api/auth/callback | ||
activate Dex | ||
Dex --> AuthAPI: Redirect to /auth/callback?code=someauthcode&state=somestate | ||
deactivate Dex | ||
AuthAPI --> WebUI: Redirect to http://webui-hostname/callback?code=someauthcode | ||
deactivate AuthAPI | ||
note left | ||
The redirect's location is the | ||
same "callback_url" provided | ||
in the GET /auth request. | ||
end note | ||
|
||
WebUI -> AuthAPI: POST /auth (client_id, client_secret, code) | ||
activate AuthAPI | ||
AuthAPI -> Dex: POST /token (client_id, client_secret, code) | ||
activate Dex | ||
Dex --> AuthAPI: Success response (JWT, refresh token) | ||
deactivate Dex | ||
AuthAPI --> WebUI: Success response (JWT, refresh token) | ||
deactivate AuthAPI | ||
|
||
WebUI --> User: Displays personal access token details | ||
deactivate WebUI | ||
@enduml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
galasa-parent/dev.galasa.framework.api.authentication/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.