intermediate commit with some methods implemented
This commit is contained in:
parent
4fcda01738
commit
2902a81161
6 changed files with 214 additions and 46 deletions
|
@ -1,6 +1,7 @@
|
|||
package op
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
httphelper "github.com/zitadel/oidc/v3/pkg/http"
|
||||
|
@ -66,3 +67,34 @@ func RequestError(w http.ResponseWriter, r *http.Request, err error, logger *slo
|
|||
logger.Log(r.Context(), e.LogLevel(), "request error", "oidc_error", e)
|
||||
httphelper.MarshalJSONWithStatus(w, e, status)
|
||||
}
|
||||
|
||||
func TryErrorRedirect(ctx context.Context, authReq ErrAuthRequest, parent error, encoder httphelper.Encoder, logger *slog.Logger) (*Redirect, error) {
|
||||
e := oidc.DefaultToServerError(parent, parent.Error())
|
||||
logger = logger.With("oidc_error", e)
|
||||
|
||||
if authReq == nil {
|
||||
logger.Log(ctx, e.LogLevel(), "auth request")
|
||||
return nil, NewStatusError(parent, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if logAuthReq, ok := authReq.(LogAuthRequest); ok {
|
||||
logger = logger.With("auth_request", logAuthReq)
|
||||
}
|
||||
|
||||
if authReq.GetRedirectURI() == "" || e.IsRedirectDisabled() {
|
||||
logger.Log(ctx, e.LogLevel(), "auth request: not redirecting")
|
||||
return nil, NewStatusError(parent, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
e.State = authReq.GetState()
|
||||
var responseMode oidc.ResponseMode
|
||||
if rm, ok := authReq.(interface{ GetResponseMode() oidc.ResponseMode }); ok {
|
||||
responseMode = rm.GetResponseMode()
|
||||
}
|
||||
url, err := AuthResponseURL(authReq.GetRedirectURI(), authReq.GetResponseType(), responseMode, e, encoder)
|
||||
if err != nil {
|
||||
logger.ErrorContext(ctx, "auth response URL", "error", err)
|
||||
return nil, NewStatusError(err, http.StatusBadRequest)
|
||||
}
|
||||
return NewRedirect(url), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue