You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add trusted origins feature
Closes#116
* Refactor Trusted Origins feature to be more like Django.
Instead of accepting []*url.URL, which can cause weird problems, now TrustedOrigins accept []string, which is the list of hosts accepted by the middleware...So the schema doesn't matter anymore and it's more friendly to use.
* Add table driven tests for the Trusted Origins feature as requested
* Fix documentation of the TrustedOrigins feature
* Add a section describing the Trusted Origins feature for Javascript applications on the README
* Add more test cases for the table driven tests for the TrustedOrigins feature
* Fix documentation of the TrustedOrigins feature so the lint error is fixed
funcGetUser(whttp.ResponseWriter, r *http.Request) {
226
+
// Authenticate the request, get the id from the route params,
227
+
// and fetch the user from the DB, etc.
228
+
229
+
// Get the token and pass it in the CSRF header. Our JSON-speaking client
230
+
// or JavaScript framework can now read the header and return the token in
231
+
// in its own "X-CSRF-Token" request header on the subsequent POST.
232
+
w.Header().Set("X-CSRF-Token", csrf.Token(r))
233
+
b, err:= json.Marshal(user)
234
+
if err != nil {
235
+
http.Error(w, err.Error(), 500)
236
+
return
237
+
}
238
+
239
+
w.Write(b)
240
+
}
241
+
```
242
+
243
+
On the example above, you're authorizing requests from `ui.domain.com` to make valid CSRF requests to your application, so you can have your API server on another domain without problems.
0 commit comments