mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-07 00:37:36 +00:00
29 lines
667 B
Go
29 lines
667 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
|
)
|
|
|
|
func apiTokenBoundUser(record *config.APITokenRecord) string {
|
|
if record == nil {
|
|
return ""
|
|
}
|
|
ownerUserID := strings.TrimSpace(apiTokenOwnerUserID(*record))
|
|
if ownerUserID == "" || strings.HasPrefix(ownerUserID, "token:") {
|
|
return ""
|
|
}
|
|
return ownerUserID
|
|
}
|
|
|
|
func apiTokenAuthenticatedUser(record *config.APITokenRecord) string {
|
|
if ownerUserID := apiTokenBoundUser(record); ownerUserID != "" {
|
|
return ownerUserID
|
|
}
|
|
if record == nil || strings.TrimSpace(record.ID) == "" {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf("token:%s", strings.TrimSpace(record.ID))
|
|
}
|