Skip to content

Commit 599d6cf

Browse files
author
raul-brainattica
committed
Refresh - Auth Services added.
1 parent 1ea230d commit 599d6cf

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

controllers/auth_controller.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package controllers
22

33
import (
4-
"api.jwt.auth/api/parameters"
54
"api.jwt.auth/core/authentication"
65
"api.jwt.auth/services"
76
"api.jwt.auth/services/models"
@@ -23,11 +22,9 @@ func Login(w http.ResponseWriter, r *http.Request) {
2322
}
2423

2524
func RefresfhToken(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
26-
authBackend := authentication.InitJWTAuthenticationBackend()
27-
token := parameters.TokenAuthentication{authBackend.GenerateToken()}
28-
response, _ := json.Marshal(token)
25+
token := services.RefreshToken()
2926
w.Header().Set("Content-Type", "application/json")
30-
w.Write(response)
27+
w.Write(token)
3128
}
3229

3330
func Logout(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {

services/auth_service.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ func Login(requestUser *models.User) (int, []byte) {
2020
return http.StatusUnauthorized, []byte("")
2121
}
2222

23-
/*func RefreshToken() {
24-
23+
func RefreshToken() []byte {
24+
authBackend := authentication.InitJWTAuthenticationBackend()
25+
token := parameters.TokenAuthentication{authBackend.GenerateToken()}
26+
response, err := json.Marshal(token)
27+
if err != nil {
28+
panic(err)
29+
}
30+
return response
2531
}
2632

27-
func Logout() {
33+
/*func Logout() {
2834
2935
}*/

0 commit comments

Comments
 (0)