-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauthorize_error.go
51 lines (39 loc) · 1.44 KB
/
authorize_error.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
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package oauth2
import (
"context"
"encoding/json"
"fmt"
"net/http"
"authelia.com/provider/oauth2/internal/consts"
)
func (f *Fosite) WriteAuthorizeError(ctx context.Context, rw http.ResponseWriter, requester AuthorizeRequester, err error) {
rw.Header().Set(consts.HeaderCacheControl, consts.CacheControlNoStore)
rw.Header().Set(consts.HeaderPragma, consts.PragmaNoCache)
for _, handler := range f.Config.GetResponseModeHandlers(ctx) {
if handler.ResponseModes().Has(requester.GetResponseMode()) {
handler.WriteAuthorizeError(ctx, rw, requester, err)
return
}
}
f.handleWriteAuthorizeErrorJSON(ctx, rw, ErrServerError.WithHint("The Authorization Server was unable to process the requested Response Mode."))
}
func (f *Fosite) handleWriteAuthorizeErrorJSON(ctx context.Context, rw http.ResponseWriter, rfc *RFC6749Error) {
rw.Header().Set(consts.HeaderContentType, consts.ContentTypeApplicationJSON)
var (
data []byte
err error
)
if data, err = json.Marshal(rfc); err != nil {
if f.Config.GetSendDebugMessagesToClients(ctx) {
errorMessage := EscapeJSONString(err.Error())
http.Error(rw, fmt.Sprintf(`{"error":"server_error","error_description":"%s"}`, errorMessage), http.StatusInternalServerError)
} else {
http.Error(rw, `{"error":"server_error"}`, http.StatusInternalServerError)
}
return
}
rw.WriteHeader(rfc.CodeField)
_, _ = rw.Write(data)
}