(w http.ResponseWriter, _ *http.Request, d *data, user *users.User, tokenExpirationTime time.Duration)
| 237 | } |
| 238 | |
| 239 | func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.User, tokenExpirationTime time.Duration) (int, error) { |
| 240 | claims := &authToken{ |
| 241 | User: userInfo{ |
| 242 | ID: user.ID, |
| 243 | Locale: user.Locale, |
| 244 | ViewMode: user.ViewMode, |
| 245 | SingleClick: user.SingleClick, |
| 246 | RedirectAfterCopyMove: user.RedirectAfterCopyMove, |
| 247 | Perm: user.Perm, |
| 248 | LockPassword: user.LockPassword, |
| 249 | Commands: user.Commands, |
| 250 | HideDotfiles: user.HideDotfiles, |
| 251 | DateFormat: user.DateFormat, |
| 252 | Username: user.Username, |
| 253 | AceEditorTheme: user.AceEditorTheme, |
| 254 | }, |
| 255 | RegisteredClaims: jwt.RegisteredClaims{ |
| 256 | IssuedAt: jwt.NewNumericDate(time.Now()), |
| 257 | ExpiresAt: jwt.NewNumericDate(time.Now().Add(tokenExpirationTime)), |
| 258 | Issuer: "File Browser", |
| 259 | }, |
| 260 | } |
| 261 | |
| 262 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) |
| 263 | signed, err := token.SignedString(d.settings.Key) |
| 264 | if err != nil { |
| 265 | return http.StatusInternalServerError, err |
| 266 | } |
| 267 | |
| 268 | w.Header().Set("Content-Type", "text/plain") |
| 269 | if _, err := w.Write([]byte(signed)); err != nil { |
| 270 | return http.StatusInternalServerError, err |
| 271 | } |
| 272 | return 0, nil |
| 273 | } |
no outgoing calls
no test coverage detected