+1
-1
cmd/client_test/main.go
+1
-1
cmd/client_test/main.go
···
133
133
db.AutoMigrate(&OauthRequest{}, &OauthSession{})
134
134
135
135
xrpcCli := &oauth.XrpcClient{
136
-
OnDPoPNonceChanged: func(did, newNonce string) {
136
+
OnDpopPdsNonceChanged: func(did, newNonce string) {
137
137
if err := db.Exec("UPDATE oauth_sessions SET dpop_pds_nonce = ? WHERE did = ?", newNonce, did).Error; err != nil {
138
138
slog.Default().Error("error updating pds nonce", "err", err)
139
139
}
+12
-5
xrpc.go
+12
-5
xrpc.go
···
19
19
"github.com/lestrrat-go/jwx/v2/jwk"
20
20
)
21
21
22
+
// This xrpc client is copied from the indigo xrpc client, with some tweaks:
23
+
// - There is no `AuthInfo` on the client. Instead, you pass auth _with the request_ in the `Do()` function
24
+
// - There is an `XrpcAuthedRequestArgs` struct that contains all the info you need to complete an authed request
25
+
// - There is a `OnDpopPdsNonceChanged` callback that will run when the dpop nonce receives an update. You can
26
+
// use this to update a database, for example.
27
+
// - Requests are retried whenever the dpop nonce changes
28
+
22
29
type XrpcClient struct {
23
30
// Client is an HTTP client to use. If not set, defaults to http.RobustHTTPClient().
24
-
Client *http.Client
25
-
UserAgent *string
26
-
Headers map[string]string
27
-
OnDPoPNonceChanged func(did, newNonce string)
31
+
Client *http.Client
32
+
UserAgent *string
33
+
Headers map[string]string
34
+
OnDpopPdsNonceChanged func(did, newNonce string)
28
35
}
29
36
30
37
type XrpcAuthedRequestArgs struct {
···
212
219
// if we get a new nonce, update the nonce and make the request again
213
220
if (resp.StatusCode == 400 || resp.StatusCode == 401) && xe.ErrStr == "use_dpop_nonce" {
214
221
authedArgs.DpopPdsNonce = resp.Header.Get("DPoP-Nonce")
215
-
c.OnDPoPNonceChanged(authedArgs.Did, authedArgs.DpopPdsNonce)
222
+
c.OnDpopPdsNonceChanged(authedArgs.Did, authedArgs.DpopPdsNonce)
216
223
continue
217
224
}
218
225