mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 23:13:11 -06:00
Implement password login stub response
This commit is contained in:
parent
baf97280f6
commit
e75b332333
|
|
@ -1,6 +1,9 @@
|
|||
package readers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/matrix-org/dendrite/clientapi/config"
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/util"
|
||||
"net/http"
|
||||
|
|
@ -15,6 +18,17 @@ type flow struct {
|
|||
Stages []string `json:"stages"`
|
||||
}
|
||||
|
||||
type passwordRequest struct {
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type loginResponse struct {
|
||||
UserID string `json:"user_id"`
|
||||
AccessToken string `json:"access_token"`
|
||||
HomeServer string `json:"home_server"`
|
||||
}
|
||||
|
||||
func passwordLogin() loginFlows {
|
||||
f := loginFlows{}
|
||||
s := flow{"m.login.password", []string{"m.login.password"}}
|
||||
|
|
@ -22,16 +36,37 @@ func passwordLogin() loginFlows {
|
|||
return f
|
||||
}
|
||||
|
||||
func Login(req *http.Request) util.JSONResponse {
|
||||
// Login implements GET and POST /login
|
||||
func Login(req *http.Request, cfg config.ClientAPI) util.JSONResponse {
|
||||
if req.Method == "GET" {
|
||||
return util.JSONResponse{
|
||||
Code: 200,
|
||||
JSON: passwordLogin(),
|
||||
}
|
||||
} else if req.Method == "POST" {
|
||||
var r passwordRequest
|
||||
resErr := httputil.UnmarshalJSONRequest(req, &r)
|
||||
if resErr != nil {
|
||||
return *resErr
|
||||
}
|
||||
if r.User == "" {
|
||||
return util.JSONResponse{
|
||||
Code: 403,
|
||||
JSON: jsonerror.Forbidden("Not implemented"),
|
||||
Code: 400,
|
||||
JSON: jsonerror.BadJSON("'user' must be supplied."),
|
||||
}
|
||||
}
|
||||
return util.JSONResponse{
|
||||
Code: 200,
|
||||
JSON: loginResponse{
|
||||
UserID: makeUserID(r.User, cfg.ServerName),
|
||||
AccessToken: makeUserID(r.User, cfg.ServerName), // FIXME: token is the user ID for now
|
||||
HomeServer: cfg.ServerName,
|
||||
},
|
||||
}
|
||||
} else if req.Method == "OPTIONS" {
|
||||
return util.JSONResponse{
|
||||
Code: 200,
|
||||
JSON: nil,
|
||||
}
|
||||
}
|
||||
return util.JSONResponse{
|
||||
|
|
@ -39,3 +74,7 @@ func Login(req *http.Request) util.JSONResponse {
|
|||
JSON: jsonerror.NotFound("Bad method"),
|
||||
}
|
||||
}
|
||||
|
||||
func makeUserID(localpart, domain string) string {
|
||||
return fmt.Sprintf("@%s:%s", localpart, domain)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI
|
|||
)
|
||||
r0mux.Handle("/login",
|
||||
make("login", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse {
|
||||
return readers.Login(req)
|
||||
return readers.Login(req, cfg)
|
||||
})),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue