forked from ory/hydra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler_fallback_endpoints.go
137 lines (126 loc) · 4.04 KB
/
handler_fallback_endpoints.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright © 2015-2018 Aeneas Rekkas <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Aeneas Rekkas <[email protected]>
* @copyright 2015-2018 Aeneas Rekkas <[email protected]>
* @license Apache-2.0
*/
package oauth2
import (
"html/template"
"net/http"
"github.com/julienschmidt/httprouter"
)
func (h *Handler) DefaultConsentHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
h.L.Warnln("It looks like no consent/login URL was set. All OAuth2 flows except client credentials will fail.")
h.L.Warnln("A client requested the default login & consent URL, environment variable OAUTH2_CONSENT_URL or OAUTH2_LOGIN_URL or both are probably not set.")
t, err := template.New("consent").Parse(`
<html>
<head>
<title>Misconfigured consent/login URL</title>
</head>
<body>
<p>
It looks like you forgot to set the consent/login provider url, which can be set using the <code>OAUTH2_CONSENT_URL</code> and <code>OAUTH2_LOGIN_URL</code>
environment variable.
</p>
<p>
If you are an administrator, please read <a href="https://www.ory.sh/docs">
the guide</a> to understand what you need to do. If you are a user, please contact the administrator.
</p>
</body>
</html>
`)
if err != nil {
h.H.WriteError(w, r, err)
return
}
if err := t.Execute(w, nil); err != nil {
h.H.WriteError(w, r, err)
return
}
}
func (h *Handler) DefaultErrorHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
h.L.Warnln("A client requested the default error URL, environment variable OAUTH2_ERROR_URL is probably not set.")
t, err := template.New("consent").Parse(`
<html>
<head>
<title>An OAuth 2.0 Error Occurred</title>
</head>
<body>
<h1>
The OAuth2 request resulted in an error.
</h1>
<ul>
<li>Error: {{ .Name }}</li>
<li>Description: {{ .Description }}</li>
<li>Hint: {{ .Hint }}</li>
<li>Debug: {{ .Debug }}</li>
</ul>
<p>
You are seeing this default error page because the administrator has not set a dedicated error URL (environment variable <code>OAUTH2_ERROR_URL</code> is not set).
If you are an administrator, please read <a href="https://www.ory.sh/docs">the guide</a> to understand what you
need to do. If you are a user, please contact the administrator.
</p>
</body>
</html>
`)
if err != nil {
h.H.WriteError(w, r, err)
return
}
if err := t.Execute(w, struct {
Name string
Description string
Hint string
Debug string
}{
Name: r.URL.Query().Get("error"),
Description: r.URL.Query().Get("error_description"),
Hint: r.URL.Query().Get("error_hint"),
Debug: r.URL.Query().Get("error_debug"),
}); err != nil {
h.H.WriteError(w, r, err)
return
}
}
func (h *Handler) DefaultLogoutHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
h.L.Warnln("A client requested the default logout URL, environment variable OAUTH2_LOGOUT_REDIRECT_URL is probably not set.")
t, err := template.New("consent").Parse(`
<html>
<head>
<title>You logged out successfully</title>
</head>
<body>
<h1>
You logged out successfully!
</h1>
<p>
You are seeing this default page because the administrator did not specify a redirect URL (environment variable <code>OAUTH2_LOGOUT_REDIRECT_URL</code> is not set).
If you are an administrator, please read <a href="https://www.ory.sh/docs">the guide</a> to understand what you
need to do. If you are a user, please contact the administrator.
</p>
</body>
</html>
`)
if err != nil {
h.H.WriteError(w, r, err)
return
}
if err := t.Execute(w, nil); err != nil {
h.H.WriteError(w, r, err)
return
}
}