2023-12-04 13:12:01 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Luzifer/twitch-bot/v3/internal/service/authcache"
|
|
|
|
)
|
|
|
|
|
|
|
|
const internalTokenAuthCacheExpiry = 5 * time.Minute
|
|
|
|
|
2024-06-12 19:26:39 +00:00
|
|
|
func authBackendInternalAppToken(token string) (modules []string, expiresAt time.Time, err error) {
|
2023-12-04 13:12:01 +00:00
|
|
|
for _, auth := range config.AuthTokens {
|
|
|
|
if auth.validate(token) != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found a matching token
|
|
|
|
return auth.Modules, time.Now().Add(internalTokenAuthCacheExpiry), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, time.Time{}, authcache.ErrUnauthorized
|
|
|
|
}
|
|
|
|
|
2024-06-12 19:26:39 +00:00
|
|
|
func authBackendInternalEditorToken(token string) ([]string, time.Time, error) {
|
2024-06-16 15:43:37 +00:00
|
|
|
_, _, expiresAt, modules, err := editorTokenService.ValidateLoginToken(token)
|
2024-06-12 19:26:39 +00:00
|
|
|
if err != nil {
|
|
|
|
// None of our tokens: Nay.
|
|
|
|
return nil, time.Time{}, authcache.ErrUnauthorized
|
|
|
|
}
|
|
|
|
|
2024-06-16 15:43:37 +00:00
|
|
|
return modules, expiresAt, nil
|
2024-06-12 19:26:39 +00:00
|
|
|
}
|