( ctx context.Context, serverName gomatrixserverlib.ServerName, userAPI userapi.ClientUserAPI, login *auth.Login, ipAddr, userAgent string, )
| 88 | } |
| 89 | |
| 90 | func completeAuth( |
| 91 | ctx context.Context, serverName gomatrixserverlib.ServerName, userAPI userapi.ClientUserAPI, login *auth.Login, |
| 92 | ipAddr, userAgent string, |
| 93 | ) util.JSONResponse { |
| 94 | token, err := auth.GenerateAccessToken() |
| 95 | if err != nil { |
| 96 | util.GetLogger(ctx).WithError(err).Error("auth.GenerateAccessToken failed") |
| 97 | return jsonerror.InternalServerError() |
| 98 | } |
| 99 | |
| 100 | localpart, err := userutil.ParseUsernameParam(login.Username(), &serverName) |
| 101 | if err != nil { |
| 102 | util.GetLogger(ctx).WithError(err).Error("auth.ParseUsernameParam failed") |
| 103 | return jsonerror.InternalServerError() |
| 104 | } |
| 105 | |
| 106 | var performRes userapi.PerformDeviceCreationResponse |
| 107 | err = userAPI.PerformDeviceCreation(ctx, &userapi.PerformDeviceCreationRequest{ |
| 108 | DeviceDisplayName: login.InitialDisplayName, |
| 109 | DeviceID: login.DeviceID, |
| 110 | AccessToken: token, |
| 111 | Localpart: localpart, |
| 112 | IPAddr: ipAddr, |
| 113 | UserAgent: userAgent, |
| 114 | }, &performRes) |
| 115 | if err != nil { |
| 116 | return util.JSONResponse{ |
| 117 | Code: http.StatusInternalServerError, |
| 118 | JSON: jsonerror.Unknown("failed to create device: " + err.Error()), |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return util.JSONResponse{ |
| 123 | Code: http.StatusOK, |
| 124 | JSON: loginResponse{ |
| 125 | UserID: performRes.Device.UserID, |
| 126 | AccessToken: performRes.Device.AccessToken, |
| 127 | HomeServer: serverName, |
| 128 | DeviceID: performRes.Device.ID, |
| 129 | }, |
| 130 | } |
| 131 | } |
no test coverage detected