providers/proxy: rework redirect mechanism (#8594)
* providers/proxy: rework redirect mechanism Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add session id, don't tie to state in session Signed-off-by: Jens Langhammer <jens@goauthentik.io> * handle state failing to parse Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * save session after creating state Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove debug Signed-off-by: Jens Langhammer <jens@goauthentik.io> * include task expiry in status Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix redirect URL detection Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@ -3,9 +3,10 @@ package hs256
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
type KeySet struct {
|
||||
@ -15,17 +16,23 @@ type KeySet struct {
|
||||
|
||||
func NewKeySet(secret string) *KeySet {
|
||||
return &KeySet{
|
||||
m: jwt.GetSigningMethod("HS256"),
|
||||
m: jwt.SigningMethodHS256,
|
||||
secret: secret,
|
||||
}
|
||||
}
|
||||
|
||||
func (ks *KeySet) VerifySignature(ctx context.Context, jwt string) ([]byte, error) {
|
||||
parts := strings.Split(jwt, ".")
|
||||
err := ks.m.Verify(strings.Join(parts[0:2], "."), parts[2], []byte(ks.secret))
|
||||
func (ks *KeySet) VerifySignature(ctx context.Context, rawJWT string) ([]byte, error) {
|
||||
_, err := jwt.Parse(rawJWT, func(token *jwt.Token) (interface{}, error) {
|
||||
// Don't forget to validate the alg is what you expect:
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
return []byte(ks.secret), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parts := strings.Split(rawJWT, ".")
|
||||
payload, err := base64.RawURLEncoding.DecodeString(parts[1])
|
||||
return payload, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user