diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-29 20:04:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-29 20:04:09 +0900 |
| commit | 648613e24c8afe5fd3c599def61b33ccf7bcb96c (patch) | |
| tree | f368aa1ef1d734d3096c9129e17d6af11d1041a6 /backend/api/generated.go | |
| parent | d73fd8bf5bf589a4a391c867e980761fadb647ce (diff) | |
| download | iosdc-japan-2024-albatross-648613e24c8afe5fd3c599def61b33ccf7bcb96c.tar.gz iosdc-japan-2024-albatross-648613e24c8afe5fd3c599def61b33ccf7bcb96c.tar.zst iosdc-japan-2024-albatross-648613e24c8afe5fd3c599def61b33ccf7bcb96c.zip | |
feat: authenticate WebSocket connection by short-lived access token
Diffstat (limited to 'backend/api/generated.go')
| -rw-r--r-- | backend/api/generated.go | 143 |
1 files changed, 121 insertions, 22 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index 7e64929..b6563c9 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -212,6 +212,11 @@ type PostLoginJSONBody struct { Username string `json:"username"` } +// GetTokenParams defines parameters for GetToken. +type GetTokenParams struct { + Authorization string `json:"Authorization"` +} + // PostLoginJSONRequestBody defines body for PostLogin for application/json ContentType. type PostLoginJSONRequestBody PostLoginJSONBody @@ -588,6 +593,9 @@ type ServerInterface interface { // User login // (POST /login) PostLogin(ctx echo.Context) error + // Get a short-lived access token + // (GET /token) + GetToken(ctx echo.Context, params GetTokenParams) error } // ServerInterfaceWrapper converts echo contexts to parameters. @@ -679,6 +687,37 @@ func (w *ServerInterfaceWrapper) PostLogin(ctx echo.Context) error { return err } +// GetToken converts echo context to params. +func (w *ServerInterfaceWrapper) GetToken(ctx echo.Context) error { + var err error + + // Parameter object where we will unmarshal all parameters from the context + var params GetTokenParams + + headers := ctx.Request().Header + // ------------- Required header parameter "Authorization" ------------- + if valueList, found := headers[http.CanonicalHeaderKey("Authorization")]; found { + var Authorization string + n := len(valueList) + if n != 1 { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for Authorization, got %d", n)) + } + + err = runtime.BindStyledParameterWithOptions("simple", "Authorization", valueList[0], &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter Authorization: %s", err)) + } + + params.Authorization = Authorization + } else { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Header parameter Authorization is required, but not found")) + } + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.GetToken(ctx, params) + return err +} + // This is a simple interface which specifies echo.Route addition functions which // are present on both echo.Echo and echo.Group, since we want to allow using // either of them for path registration @@ -710,6 +749,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.GET(baseURL+"/games", wrapper.GetGames) router.GET(baseURL+"/games/:game_id", wrapper.GetGamesGameId) router.POST(baseURL+"/login", wrapper.PostLogin) + router.GET(baseURL+"/token", wrapper.GetToken) } @@ -802,6 +842,36 @@ func (response PostLogin401JSONResponse) VisitPostLoginResponse(w http.ResponseW return json.NewEncoder(w).Encode(response) } +type GetTokenRequestObject struct { + Params GetTokenParams +} + +type GetTokenResponseObject interface { + VisitGetTokenResponse(w http.ResponseWriter) error +} + +type GetToken200JSONResponse struct { + Token string `json:"token"` +} + +func (response GetToken200JSONResponse) VisitGetTokenResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type GetToken403JSONResponse struct { + Message string `json:"message"` +} + +func (response GetToken403JSONResponse) VisitGetTokenResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(403) + + return json.NewEncoder(w).Encode(response) +} + // StrictServerInterface represents all server handlers. type StrictServerInterface interface { // List games @@ -813,6 +883,9 @@ type StrictServerInterface interface { // User login // (POST /login) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) + // Get a short-lived access token + // (GET /token) + GetToken(ctx context.Context, request GetTokenRequestObject) (GetTokenResponseObject, error) } type StrictHandlerFunc = strictecho.StrictEchoHandlerFunc @@ -907,31 +980,57 @@ func (sh *strictHandler) PostLogin(ctx echo.Context) error { return nil } +// GetToken operation middleware +func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error { + var request GetTokenRequestObject + + request.Params = params + + handler := func(ctx echo.Context, request interface{}) (interface{}, error) { + return sh.ssi.GetToken(ctx.Request().Context(), request.(GetTokenRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "GetToken") + } + + response, err := handler(ctx, request) + + if err != nil { + return err + } else if validResponse, ok := response.(GetTokenResponseObject); ok { + return validResponse.VisitGetTokenResponse(ctx.Response()) + } else if response != nil { + return fmt.Errorf("unexpected response type: %T", response) + } + return nil +} + // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9xYbW/bNhD+Kxo3oBsg+C1B0PlblnVZig4z6g37UAQGLZ1tZhSp8qg6XqD/PpDUi2XJ", - "luwI27B+SBPp7vjc3XMv4gsJZBRLAUIjmb4QDDYQUfvrPY3A/B8rGYPSDOzTkGHM6W4hsrfwTKOYA5la", - "eW9MfKJ3sfkbtWJiTVKfhImimkmxQAikCLGid3UzKlSY0LAGZXTWNIIFCyui4ybBWMklh8gIfqNgRabk", - "62Hp0zBzaDjLxFKfoKZKQ7igumL9++ubm7fXb0eNcFBT7fwVSUSmn0jAJUJIfLKlTDOxXoDQysSofGLP", - "IQYhxFQByU42QbH+uV9WTDDcQEge/b1gFuYPgpn6RMHnhCkIDYo8SjlAv5qfhtA/Fibl8gkCbZwzmZtx", - "ugP1CyDStXVUCvh1RaafToe1pjqf3JHUP1PpbjIn6WMTEvPmcjB3k/k7odXuIkQfgYaXad7JEI77Y9/W", - "64pq2sbhY9ZmdMclDU0qXW5NVQvUZEpiKz4NJjgNzLlthL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vv8WcotnWv9vNn8zIVnMHGPng5R0lB1uEDoIY", + "cBMK84Lq8T202ydKvfDwAnUoh8MlqdeA3U7VwBO2B6Bmp+4b+vD/m8bWAgOt6/TaI6fSelMkNf51xnmb", + "UjtjvzRf4umdiCcOqHZ7PUk23Ig6DOM/nVFvH/afu/8O561ay+AXBW3U4ZGS84SadV1lxGO6Ahzdq7U8", + "u09Wrao4pyzmsqa5pAKralgoJYBKK51iS71NLtoKx4o2vbBQOvNZnLJlpHF7UuJui/CsWuF2wgsYaZ4Y", + "ruoOkw9rjgHHgAbF/tbW6v2rXg3HcCN2fM9RtV3Ete+QPgbeUljD3nTamuByqdxnrD+bXIoFNVohBhaY", + "llQED7AILmc3JCSfQaMLAxmfnZ+NLWaVgKQJJ1NycTY+G5OQWE65wI1WNPYhXIErChtVd311w8iUXIO5", + "dgJWRdMYDGh0a5FlFvmUgvuC93yo9ynXKqqP7+2SyrXXQBnoSv0yNWul+T/ueLIdOd/EGybLKN9ZYUyU", + "RO/LZDzOO48B6dyiSSJ45CyP7tGzpLJXJ1MZEm4gxj69sGp3hGpNN62XhrgnuzXuknccTaCWgdfIQvJy", + "fPEEX+JqWa4I+6vSC84YyKDMdid1C0N9fCjtOyuYxjHVm8K33LEszLk3+pLfqGadLLQ/btgeLro2WXKp", + "uqXtZNFzJmY38ZrRv3Qh/sqocw0moLljljpCrfxsSxS2MGam0LxzIh4KoPlZ+ZvBE6ORUMQHpdnO50T+", + "9Hxy0TZYnjgr85FYHt0ewDobs0FboVF/w85EfbT/zrZ+dq9xzkif7N/6bXuZCrEJaGrWII2FCszT+Xxo", + "Ot/Iz1RwFkQamD2LChyUzoX9IpuB0kGZzjrD/0TQgae1Y3gZ+n0t8YMTaG+Gz3W0PjM+fWXtEddKmx8F", + "/wwsoM7zwMcqy7Ls3wAAAP//jcdHSHceAAA=", } // GetSwagger returns the content of the embedded swagger specification file |
