mirror of
https://github.com/1f349/tulip.git
synced 2024-11-14 15:51:40 +00:00
Start writing purple auth source
This commit is contained in:
parent
0926bf9327
commit
52bdca34e6
32
cmd/purple-tulip/server/auth-source.go
Normal file
32
cmd/purple-tulip/server/auth-source.go
Normal 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!=
|
||||
}
|
Loading…
Reference in New Issue
Block a user