feat(chiauth): add GetJWS(r) helper

このコミットが含まれているのは:
AJ ONeal 2022-05-09 15:14:12 -06:00
コミット 97d0f2eec0
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 562702827EF68D87
3個のファイルの変更11行の追加7行の削除

ファイルの表示

@ -39,9 +39,8 @@ func main() {
r.Use(tokenVerifier)
r.Post("/api/users/profile", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
jws, ok := ctx.Value(chiauth.JWSKey).(*libauth.JWS)
if !ok || !jws.Trusted {
jws := chiauth.GetJWS(r)
if nil == jws || !jws.Trusted {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}

ファイルの表示

@ -88,3 +88,10 @@ func NewTokenVerifier(opts VerificationParams) func(http.Handler) http.Handler {
})
}
}
// GetJWS retrieves *libauth.JWS from r.Context()
func GetJWS(r *http.Request) *libauth.JWS {
ctx := r.Context()
jws, _ := ctx.Value(JWSKey).(*libauth.JWS)
return jws
}

ファイルの表示

@ -10,7 +10,6 @@ import (
"github.com/go-chi/chi/v5"
"git.rootprojects.org/root/keypairs/keyfetch"
"git.rootprojects.org/root/libauth"
"git.rootprojects.org/root/libauth/chiauth"
)
@ -38,9 +37,8 @@ func main() {
r.Use(tokenVerifier)
r.Post("/api/users/profile", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
jws, ok := ctx.Value(chiauth.JWSKey).(*libauth.JWS)
if !ok || !jws.Trusted {
jws := chiauth.GetJWS(r)
if nil == jws || !jws.Trusted {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}