mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
👽️ Introduced /login InhibitDevice for 2FA Initial Login Phase.
This commit is contained in:
parent
37fcdf67c2
commit
b0955b532b
|
|
@ -44,7 +44,8 @@ func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.C
|
|||
}
|
||||
|
||||
var header struct {
|
||||
Type string `json:"type"`
|
||||
Type string `json:"type"`
|
||||
InhibitDevice bool `json:"inhibit_device"`
|
||||
}
|
||||
if err := json.Unmarshal(reqBytes, &header); err != nil {
|
||||
err := &util.JSONResponse{
|
||||
|
|
@ -58,9 +59,10 @@ func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.C
|
|||
switch header.Type {
|
||||
case authtypes.LoginTypePassword:
|
||||
typ = &LoginTypePassword{
|
||||
UserApi: useraccountAPI,
|
||||
Config: cfg,
|
||||
Rt: rt,
|
||||
UserApi: useraccountAPI,
|
||||
Config: cfg,
|
||||
Rt: rt,
|
||||
InhibitDevice: header.InhibitDevice,
|
||||
}
|
||||
case authtypes.LoginTypeToken:
|
||||
typ = &LoginTypeToken{
|
||||
|
|
|
|||
|
|
@ -42,9 +42,10 @@ const email = "email"
|
|||
|
||||
// LoginTypePassword implements https://matrix.org/docs/spec/client_server/r0.6.1#password-based
|
||||
type LoginTypePassword struct {
|
||||
UserApi api.ClientUserAPI
|
||||
Config *config.ClientAPI
|
||||
Rt *ratelimit.RtFailedLogin
|
||||
UserApi api.ClientUserAPI
|
||||
Config *config.ClientAPI
|
||||
Rt *ratelimit.RtFailedLogin
|
||||
InhibitDevice bool
|
||||
}
|
||||
|
||||
func (t *LoginTypePassword) Name() string {
|
||||
|
|
@ -61,6 +62,7 @@ func (t *LoginTypePassword) LoginFromJSON(ctx context.Context, reqBytes []byte)
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
login.InhibitDevice = t.InhibitDevice
|
||||
|
||||
return login, func(context.Context, *util.JSONResponse) {}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ type LoginIdentifier struct {
|
|||
type Login struct {
|
||||
LoginIdentifier // Flat fields deprecated in favour of `identifier`.
|
||||
Identifier LoginIdentifier `json:"identifier"`
|
||||
InhibitDevice bool `json:"inhibit_device,omitempty"`
|
||||
|
||||
// Both DeviceID and InitialDisplayName can be omitted, or empty strings ("")
|
||||
// Thus a pointer is needed to differentiate between the two
|
||||
|
|
|
|||
|
|
@ -69,6 +69,17 @@ func Login(
|
|||
if authErr != nil {
|
||||
return *authErr
|
||||
}
|
||||
if login.InhibitDevice {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: loginResponse{
|
||||
UserID: login.Username(),
|
||||
AccessToken: "",
|
||||
HomeServer: cfg.Matrix.ServerName,
|
||||
DeviceID: "",
|
||||
},
|
||||
}
|
||||
}
|
||||
// make a device/access token
|
||||
authErr2 := completeAuth(req.Context(), cfg.Matrix.ServerName, userAPI, login, req.RemoteAddr, req.UserAgent())
|
||||
cleanup(req.Context(), &authErr2)
|
||||
|
|
|
|||
Loading…
Reference in a new issue