MCPcopy
hub / github.com/gotify/server / RequireClient

Method RequireClient

auth/authentication.go:57–75  ·  view source on GitHub ↗

RequireClient returns a gin middleware which requires a client token or basic authentication header to be supplied with the request.

()

Source from the content-addressed store, hash-verified

55// RequireClient returns a gin middleware which requires a client token or basic authentication header to be supplied
56// with the request.
57func (a *Auth) RequireClient() gin.HandlerFunc {
58 return a.requireToken(func(tokenID string, user *model.User) (bool, bool, uint, error) {
59 if user != nil {
60 return true, true, user.ID, nil
61 }
62 if client, err := a.DB.GetClientByToken(tokenID); err != nil {
63 return false, false, 0, err
64 } else if client != nil {
65 now := time.Now()
66 if client.LastUsed == nil || client.LastUsed.Add(5*time.Minute).Before(now) {
67 if err := a.DB.UpdateClientTokensLastUsed([]string{tokenID}, &now); err != nil {
68 return false, false, 0, err
69 }
70 }
71 return true, true, client.UserID, nil
72 }
73 return false, false, 0, nil
74 })
75}
76
77// RequireApplicationToken returns a gin middleware which requires an application token to be supplied with the request.
78func (a *Auth) RequireApplicationToken() gin.HandlerFunc {

Callers 1

CreateFunction · 0.95

Calls 3

requireTokenMethod · 0.95
GetClientByTokenMethod · 0.65

Tested by

no test coverage detected