bump backend auth module to fix telegram auth

This commit is contained in:
Dmitry Verkhoturov
2021-08-17 16:33:53 -05:00
committed by Umputun
parent f0ae4b6de8
commit fd5df39fe2
6 changed files with 20 additions and 9 deletions
+1 -1
View File
@@ -217,7 +217,7 @@ func (ah *AppleHandler) initPrivateKey() error {
return nil
}
// tokenKeyFunc use for verify JWT sign, it receive the parsed token and should return the key for validating.
// tokenKeyFunc use for verify JWT sign, it receives the parsed token and should return the key for validating.
func (ah *AppleHandler) tokenKeyFunc(jwtToken *jwt.Token) (interface{}, error) {
if jwtToken == nil {
return nil, errors.New("failed to call token keyFunc, because token is nil")
+14 -5
View File
@@ -192,9 +192,15 @@ func (th *TelegramHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
token, err := randToken()
if err != nil {
rest.SendErrorJSON(w, r, th.L, http.StatusInternalServerError, err, "failed to generate code")
return
}
th.requests.Lock()
if th.requests.data == nil {
th.requests.Unlock()
rest.SendErrorJSON(w, r, th.L, http.StatusInternalServerError, errors.New("run goroutine is not running"), "failed to process login request")
return
}
th.requests.data[token] = tgAuthRequest{
expires: time.Now().Add(tgAuthRequestLifetime),
}
@@ -236,8 +242,11 @@ func (th *TelegramHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
claims := authtoken.Claims{
User: &u,
StandardClaims: jwt.StandardClaims{
Id: queryToken,
Issuer: th.ProviderName,
Audience: r.URL.Query().Get("site"),
Id: queryToken,
Issuer: th.ProviderName,
ExpiresAt: time.Now().Add(30 * time.Minute).Unix(),
NotBefore: time.Now().Add(-1 * time.Minute).Unix(),
},
SessionOnly: false, // TODO
}
@@ -255,11 +264,11 @@ func (th *TelegramHandler) LoginHandler(w http.ResponseWriter, r *http.Request)
delete(th.requests.data, queryToken)
}
// AuthHandler does nothing since we're don't have any callbacks
func (th *TelegramHandler) AuthHandler(w http.ResponseWriter, r *http.Request) {}
// AuthHandler does nothing since we don't have any callbacks
func (th *TelegramHandler) AuthHandler(_ http.ResponseWriter, _ *http.Request) {}
// LogoutHandler - GET /logout
func (th *TelegramHandler) LogoutHandler(w http.ResponseWriter, r *http.Request) {
func (th *TelegramHandler) LogoutHandler(w http.ResponseWriter, _ *http.Request) {
th.TokenService.Reset(w)
}