Start writing purple auth source

This commit is contained in:
Melon 2024-02-03 00:48:22 +00:00
parent 0926bf9327
commit 52bdca34e6
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -0,0 +1,32 @@
package server
import (
"github.com/1f349/mjwt"
"github.com/1f349/mjwt/auth"
"github.com/1f349/tulip/database"
"github.com/1f349/tulip/oauth"
"net/http"
)
type PurpleAuthSource struct {
DB *database.DB
Signer mjwt.Signer
}
var _ oauth.AuthSource = &PurpleAuthSource{}
func (p *PurpleAuthSource) UserAuthorization(rw http.ResponseWriter, req *http.Request) (string, error) {
c := req.Cookie("auth")
if c.Value == "" {
http.Error(rw, "No auth", http.StatusForbidden)
return
}
_, b, err := mjwt.ExtractClaims[auth.AccessTokenClaims](p.Signer, c.Value)
if err != nil {
http.Error(rw, "Invalid token", http.StatusForbidden)
return
}
if b.Issuer!=
}