forked from canonical/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_write.go
38 lines (32 loc) · 1.16 KB
/
device_write.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
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package fosite
import (
"context"
"net/http"
)
// WriteDeviceResponse writes the device response
func (f *Fosite) WriteDeviceResponse(ctx context.Context, rw http.ResponseWriter, requester DeviceRequester, responder DeviceResponder) {
// Set custom headers, e.g. "X-MySuperCoolCustomHeader" or "X-DONT-CACHE-ME"...
wh := rw.Header()
rh := responder.GetHeader()
for k := range rh {
wh.Set(k, rh.Get(k))
}
rw.Header().Set("Content-Type", "application/json;charset=UTF-8")
rw.Header().Set("Cache-Control", "no-store")
rw.Header().Set("Pragma", "no-cache")
deviceResponse := &DeviceResponse{
DeviceCode: responder.GetDeviceCode(),
UserCode: responder.GetUserCode(),
VerificationURI: responder.GetVerificationURI(),
VerificationURIComplete: responder.GetVerificationURIComplete(),
ExpiresIn: responder.GetExpiresIn(),
Interval: responder.GetInterval(),
}
err := deviceResponse.ToJson(rw)
if err != nil {
http.Error(rw, ErrServerError.WithWrap(err).WithDebug(err.Error()).Error(), http.StatusInternalServerError)
return
}
}