Cardata: display oauth user code (#25818)

This commit is contained in:
andig 2025-12-09 08:32:05 +01:00 • committed by GitHub
parent 157f9d207c
commit c5fc4b4f99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 993 additions and 220 deletions

View file

@ -18,7 +18,9 @@ type errorResponse struct {
}
type loginResponse struct {
LoginUri string `json:"loginUri"`
LoginUri string `json:"loginUri"`
Code string `json:"code,omitempty"`
Expiry *time.Time `json:"expiry,omitempty"`
}
// jsonWrite writes a JSON response
@ -104,13 +106,27 @@ func (a *Handler) handleLogin(w http.ResponseWriter, r *http.Request) {
delete(a.states, encryptedState)
})
uri, err := provider.Login(encryptedState)
uri, da, err := provider.Login(encryptedState)
if err != nil {
jsonError(w, http.StatusBadRequest, err.Error())
return
}
jsonWrite(w, loginResponse{LoginUri: uri})
res := loginResponse{
LoginUri: uri,
}
if da != nil {
res.Expiry = &da.Expiry
if da.VerificationURIComplete != "" {
res.LoginUri = da.VerificationURIComplete
} else {
res.LoginUri = da.VerificationURI
res.Code = da.UserCode
}
}
jsonWrite(w, res)
}
func (a *Handler) handleLogout(w http.ResponseWriter, r *http.Request) {