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

Method RequireApplicationToken

auth/authentication.go:78–96  ·  view source on GitHub ↗

RequireApplicationToken returns a gin middleware which requires an application token to be supplied with the request.

()

Source from the content-addressed store, hash-verified

76
77// RequireApplicationToken returns a gin middleware which requires an application token to be supplied with the request.
78func (a *Auth) RequireApplicationToken() gin.HandlerFunc {
79 return a.requireToken(func(tokenID string, user *model.User) (bool, bool, uint, error) {
80 if user != nil {
81 return true, false, 0, nil
82 }
83 if app, err := a.DB.GetApplicationByToken(tokenID); err != nil {
84 return false, false, 0, err
85 } else if app != nil {
86 now := time.Now()
87 if app.LastUsed == nil || app.LastUsed.Add(5*time.Minute).Before(now) {
88 if err := a.DB.UpdateApplicationTokenLastUsed(tokenID, &now); err != nil {
89 return false, false, 0, err
90 }
91 }
92 return true, true, app.UserID, nil
93 }
94 return false, false, 0, nil
95 })
96}
97
98func (a *Auth) tokenFromQueryOrHeader(ctx *gin.Context) string {
99 if token := a.tokenFromQuery(ctx); token != "" {

Callers 2

CreateFunction · 0.95
TestNothingProvidedMethod · 0.80

Calls 3

requireTokenMethod · 0.95
GetApplicationByTokenMethod · 0.65

Tested by 1

TestNothingProvidedMethod · 0.64