Merge pull request #86 from globekeeper/daniel/auth-profile-api

🔒 Make /profile API authenticated.
This commit is contained in:
Daniel Aloni 2024-05-22 15:38:21 +03:00 committed by GitHub
commit b23f2416e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -447,6 +447,7 @@ func TestSetDisplayname(t *testing.T) {
// check profile after initial account creation
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/_matrix/client/v3/profile/"+tc.user.ID, strings.NewReader(""))
req.Header.Set("Authorization", "Bearer "+accessTokens[tc.user].accessToken)
t.Logf("%s", req.URL.String())
routers.Client.ServeHTTP(rec, req)
@ -559,6 +560,7 @@ func TestSetAvatarURL(t *testing.T) {
// check profile after initial account creation
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/_matrix/client/v3/profile/"+tc.user.ID, strings.NewReader(""))
req.Header.Set("Authorization", "Bearer "+accessTokens[tc.user].accessToken)
t.Logf("%s", req.URL.String())
routers.Client.ServeHTTP(rec, req)

View file

@ -888,9 +888,9 @@ func Setup(
).Methods(http.MethodPut)
// Element user settings
// GK-CUSTOMIZATION: Make /profile endpoints authenticated
v3mux.Handle("/profile/{userID}",
httputil.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
httputil.MakeAuthAPI("profile", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
if err != nil {
return util.ErrorResponse(err)