diff options
author | Kegsay <kegan@matrix.org> | 2020-06-16 14:10:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-16 14:10:55 +0100 |
commit | 9c77022513f400db59409f5b55fc6223d38d6bb8 (patch) | |
tree | 52223755553ef4d7065747528e40c27a79a71dff /userapi/inthttp | |
parent | 57b7fa3db801c27190bfd143cfebe98e3d76a6ae (diff) |
Make userapi responsible for checking access tokens (#1133)
* Make userapi responsible for checking access tokens
There's still plenty of dependencies on account/device DBs, but this
is a start. This is a breaking change as it adds a required config
value `listen.user_api`.
* Cleanup
* Review comments and test fix
Diffstat (limited to 'userapi/inthttp')
-rw-r--r-- | userapi/inthttp/client.go | 15 | ||||
-rw-r--r-- | userapi/inthttp/server.go | 13 |
2 files changed, 27 insertions, 1 deletions
diff --git a/userapi/inthttp/client.go b/userapi/inthttp/client.go index 90cc54a4..022243fa 100644 --- a/userapi/inthttp/client.go +++ b/userapi/inthttp/client.go @@ -26,7 +26,8 @@ import ( // HTTP paths for the internal HTTP APIs const ( - QueryProfilePath = "/userapi/queryProfile" + QueryProfilePath = "/userapi/queryProfile" + QueryAccessTokenPath = "/userapi/queryAccessToken" ) // NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API. @@ -60,3 +61,15 @@ func (h *httpUserInternalAPI) QueryProfile( apiURL := h.apiURL + QueryProfilePath return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } + +func (h *httpUserInternalAPI) QueryAccessToken( + ctx context.Context, + request *api.QueryAccessTokenRequest, + response *api.QueryAccessTokenResponse, +) error { + span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAccessToken") + defer span.Finish() + + apiURL := h.apiURL + QueryAccessTokenPath + return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response) +} diff --git a/userapi/inthttp/server.go b/userapi/inthttp/server.go index f3c17ccd..495b161c 100644 --- a/userapi/inthttp/server.go +++ b/userapi/inthttp/server.go @@ -38,4 +38,17 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) + internalAPIMux.Handle(QueryAccessTokenPath, + httputil.MakeInternalAPI("queryAccessToken", func(req *http.Request) util.JSONResponse { + request := api.QueryAccessTokenRequest{} + response := api.QueryAccessTokenResponse{} + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + if err := s.QueryAccessToken(req.Context(), &request, &response); err != nil { + return util.ErrorResponse(err) + } + return util.JSONResponse{Code: http.StatusOK, JSON: &response} + }), + ) } |