···36 Hostname string
37}
38000039func NewManager(args ManagerArgs) *Manager {
40 if args.Logger == nil {
41 args.Logger = slog.Default()
···194 nonce, _ := claims["nonce"].(string)
195 if nonce == "" {
196 // WARN: this _must_ be `use_dpop_nonce` for clients know they should make another request
197- return nil, errors.New("use_dpop_nonce")
198 }
199200 if nonce != "" && !dm.nonce.Check(nonce) {
201 // WARN: this _must_ be `use_dpop_nonce` so that clients will fetch a new nonce
202- return nil, errors.New("use_dpop_nonce")
203 }
204205 ath, _ := claims["ath"].(string)
···36 Hostname string
37}
3839+var (
40+ ErrUseDpopNonce = errors.New("use_dpop_nonce")
41+)
42+43func NewManager(args ManagerArgs) *Manager {
44 if args.Logger == nil {
45 args.Logger = slog.Default()
···198 nonce, _ := claims["nonce"].(string)
199 if nonce == "" {
200 // WARN: this _must_ be `use_dpop_nonce` for clients know they should make another request
201+ return nil, ErrUseDpopNonce
202 }
203204 if nonce != "" && !dm.nonce.Check(nonce) {
205 // WARN: this _must_ be `use_dpop_nonce` so that clients will fetch a new nonce
206+ return nil, ErrUseDpopNonce
207 }
208209 ath, _ := claims["ath"].(string)
+8-1
server/handle_oauth_par.go
···1package server
23import (
04 "time"
56 "github.com/Azure/go-autorest/autorest/to"
7 "github.com/haileyok/cocoon/internal/helpers"
8 "github.com/haileyok/cocoon/oauth"
9 "github.com/haileyok/cocoon/oauth/constants"
010 "github.com/haileyok/cocoon/oauth/provider"
11 "github.com/labstack/echo/v4"
12)
···31 // TODO: this seems wrong. should be a way to get the entire request url i believe, but this will work for now
32 dpopProof, err := s.oauthProvider.DpopManager.CheckProof(e.Request().Method, "https://"+s.config.Hostname+e.Request().URL.String(), e.Request().Header, nil)
33 if err != nil {
0000034 s.logger.Error("error getting dpop proof", "error", err)
35- return helpers.InputError(e, to.StringPtr(err.Error()))
36 }
3738 client, clientAuth, err := s.oauthProvider.AuthenticateClient(e.Request().Context(), parRequest.AuthenticateClientRequestBase, dpopProof, &provider.AuthenticateClientOptions{
···1package server
23import (
4+ "errors"
5 "time"
67 "github.com/Azure/go-autorest/autorest/to"
8 "github.com/haileyok/cocoon/internal/helpers"
9 "github.com/haileyok/cocoon/oauth"
10 "github.com/haileyok/cocoon/oauth/constants"
11+ "github.com/haileyok/cocoon/oauth/dpop"
12 "github.com/haileyok/cocoon/oauth/provider"
13 "github.com/labstack/echo/v4"
14)
···33 // TODO: this seems wrong. should be a way to get the entire request url i believe, but this will work for now
34 dpopProof, err := s.oauthProvider.DpopManager.CheckProof(e.Request().Method, "https://"+s.config.Hostname+e.Request().URL.String(), e.Request().Header, nil)
35 if err != nil {
36+ if errors.Is(err, dpop.ErrUseDpopNonce) {
37+ return e.JSON(401, map[string]string{
38+ "error": "use_dpop_nonce",
39+ })
40+ }
41 s.logger.Error("error getting dpop proof", "error", err)
42+ return helpers.InputError(e, nil)
43 }
4445 client, clientAuth, err := s.oauthProvider.AuthenticateClient(e.Request().Context(), parRequest.AuthenticateClientRequestBase, dpopProof, &provider.AuthenticateClientOptions{