summaryrefslogtreecommitdiffstats
path: root/app/user.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-27 09:21:48 -0400
committerGitHub <noreply@github.com>2017-03-27 09:21:48 -0400
commit58397f853a31773f24ad4e62dc1f34df0a975d53 (patch)
treec2055df17b6347199bf48054d606cf1b3b0e89c2 /app/user.go
parenta0d5c01dfd97b45478353ccff777de677f088d0f (diff)
downloadchat-58397f853a31773f24ad4e62dc1f34df0a975d53.tar.gz
chat-58397f853a31773f24ad4e62dc1f34df0a975d53.tar.bz2
chat-58397f853a31773f24ad4e62dc1f34df0a975d53.zip
Implement some MFA endpoints for APIv4 (#5864)
Diffstat (limited to 'app/user.go')
-rw-r--r--app/user.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/user.go b/app/user.go
index 33d052708..850b26f1b 100644
--- a/app/user.go
+++ b/app/user.go
@@ -5,6 +5,7 @@ package app
import (
"bytes"
+ b64 "encoding/base64"
"fmt"
"hash/fnv"
"image"
@@ -554,6 +555,27 @@ func GetUsersByIds(userIds []string, asAdmin bool) ([]*model.User, *model.AppErr
}
}
+func GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppError) {
+ mfaInterface := einterfaces.GetMfaInterface()
+ if mfaInterface == nil {
+ return nil, model.NewAppError("generateMfaSecret", "api.user.generate_mfa_qr.not_available.app_error", nil, "", http.StatusNotImplemented)
+ }
+
+ var user *model.User
+ var err *model.AppError
+ if user, err = GetUser(userId); err != nil {
+ return nil, err
+ }
+
+ secret, img, err := mfaInterface.GenerateSecret(user)
+ if err != nil {
+ return nil, err
+ }
+
+ mfaSecret := &model.MfaSecret{Secret: secret, QRCode: b64.StdEncoding.EncodeToString(img)}
+ return mfaSecret, nil
+}
+
func ActivateMfa(userId, token string) *model.AppError {
mfaInterface := einterfaces.GetMfaInterface()
if mfaInterface == nil {