2022-03-08 20:28:09 +00:00
|
|
|
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
2020-12-01 22:53:22 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package fositestorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ory/fosite"
|
|
|
|
|
|
|
|
"go.pinniped.dev/internal/constable"
|
2021-06-15 16:27:30 +00:00
|
|
|
"go.pinniped.dev/internal/oidc/clientregistry"
|
2021-10-06 22:28:13 +00:00
|
|
|
"go.pinniped.dev/internal/psession"
|
2020-12-01 22:53:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-12-04 22:31:06 +00:00
|
|
|
ErrInvalidRequestType = constable.Error("requester must be of type fosite.Request")
|
2021-06-15 16:27:30 +00:00
|
|
|
ErrInvalidClientType = constable.Error("requester's client must be of type clientregistry.Client")
|
2021-10-06 22:28:13 +00:00
|
|
|
ErrInvalidSessionType = constable.Error("requester's session must be of type PinnipedSession")
|
2022-03-08 20:28:09 +00:00
|
|
|
StorageRequestIDLabelName = "storage.pinniped.dev/request-id"
|
2020-12-01 22:53:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ValidateAndExtractAuthorizeRequest(requester fosite.Requester) (*fosite.Request, error) {
|
|
|
|
request, ok1 := requester.(*fosite.Request)
|
|
|
|
if !ok1 {
|
|
|
|
return nil, ErrInvalidRequestType
|
|
|
|
}
|
2021-06-15 16:27:30 +00:00
|
|
|
_, ok2 := request.Client.(*clientregistry.Client)
|
2020-12-01 22:53:22 +00:00
|
|
|
if !ok2 {
|
|
|
|
return nil, ErrInvalidClientType
|
|
|
|
}
|
2021-10-06 22:28:13 +00:00
|
|
|
_, ok3 := request.Session.(*psession.PinnipedSession)
|
2020-12-01 22:53:22 +00:00
|
|
|
if !ok3 {
|
|
|
|
return nil, ErrInvalidSessionType
|
|
|
|
}
|
|
|
|
|
|
|
|
return request, nil
|
|
|
|
}
|