-
Notifications
You must be signed in to change notification settings - Fork 371
/
Copy pathresponse_handler.go
57 lines (47 loc) · 1.88 KB
/
response_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright © 2025 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package fosite
import (
"context"
"net/http"
)
// ResponseModeHandler provides a contract for handling custom response modes
type ResponseModeHandler interface {
// ResponseModes returns a set of supported response modes handled
// by the interface implementation.
//
// In an authorize request with any of the provide response modes
// methods `WriteAuthorizeResponse` and `WriteAuthorizeError` will be
// invoked to write the successful or error authorization responses respectively.
ResponseModes() ResponseModeTypes
// WriteAuthorizeResponse writes successful responses
//
// Following headers are expected to be set by default:
// header.Set("Cache-Control", "no-store")
// header.Set("Pragma", "no-cache")
WriteAuthorizeResponse(ctx context.Context, rw http.ResponseWriter, ar AuthorizeRequester, resp AuthorizeResponder)
// WriteAuthorizeError writes error responses
//
// Following headers are expected to be set by default:
// header.Set("Cache-Control", "no-store")
// header.Set("Pragma", "no-cache")
WriteAuthorizeError(ctx context.Context, rw http.ResponseWriter, ar AuthorizeRequester, err error)
}
type ResponseModeTypes []ResponseModeType
func (rs ResponseModeTypes) Has(item ResponseModeType) bool {
for _, r := range rs {
if r == item {
return true
}
}
return false
}
func NewDefaultResponseModeHandler() *DefaultResponseModeHandler {
return new(DefaultResponseModeHandler)
}
type DefaultResponseModeHandler struct{}
func (d *DefaultResponseModeHandler) ResponseModes() ResponseModeTypes { return nil }
func (d *DefaultResponseModeHandler) WriteAuthorizeResponse(ctx context.Context, rw http.ResponseWriter, ar AuthorizeRequester, resp AuthorizeResponder) {
}
func (d *DefaultResponseModeHandler) WriteAuthorizeError(ctx context.Context, rw http.ResponseWriter, ar AuthorizeRequester, err error) {
}