handleApplicationServiceRegistration handles the registration of an application service's user by validating the AS from its access token and registering the user. Its two first parameters must be the two return values of the auth.ExtractAccessToken function. Returns an error if the access token cou
( accessToken string, tokenErr error, req *http.Request, r registerRequest, cfg *config.ClientAPI, userAPI userapi.ClientUserAPI, )
| 788 | // token doesn't belong to a valid AS, or if there was an issue completing the |
| 789 | // registration process. |
| 790 | func handleApplicationServiceRegistration( |
| 791 | accessToken string, |
| 792 | tokenErr error, |
| 793 | req *http.Request, |
| 794 | r registerRequest, |
| 795 | cfg *config.ClientAPI, |
| 796 | userAPI userapi.ClientUserAPI, |
| 797 | ) util.JSONResponse { |
| 798 | // Check if we previously had issues extracting the access token from the |
| 799 | // request. |
| 800 | if tokenErr != nil { |
| 801 | return util.JSONResponse{ |
| 802 | Code: http.StatusUnauthorized, |
| 803 | JSON: jsonerror.MissingToken(tokenErr.Error()), |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | // Check application service register user request is valid. |
| 808 | // The application service's ID is returned if so. |
| 809 | appserviceID, err := validateApplicationService( |
| 810 | cfg, r.Username, accessToken, |
| 811 | ) |
| 812 | if err != nil { |
| 813 | return *err |
| 814 | } |
| 815 | |
| 816 | // If no error, application service was successfully validated. |
| 817 | // Don't need to worry about appending to registration stages as |
| 818 | // application service registration is entirely separate. |
| 819 | return completeRegistration( |
| 820 | req.Context(), userAPI, r.Username, "", appserviceID, req.RemoteAddr, req.UserAgent(), r.Auth.Session, |
| 821 | r.InhibitLogin, r.InitialDisplayName, r.DeviceID, userapi.AccountTypeAppService, |
| 822 | ) |
| 823 | } |
| 824 | |
| 825 | // checkAndCompleteFlow checks if a given registration flow is completed given |
| 826 | // a set of allowed flows. If so, registration is completed, otherwise a |
no test coverage detected