-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathdevice_write.go
40 lines (34 loc) · 1.2 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
39
40
// Copyright © 2025 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package fosite
import (
"context"
"encoding/json"
"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(),
}
r, err := json.Marshal(deviceResponse)
rw.Write(r)
if err != nil {
http.Error(rw, ErrServerError.WithWrap(err).WithDebug(err.Error()).Error(), http.StatusInternalServerError)
return
}
}