HandleListAPIKeys lists API keys for the authenticated user (without key values).
(w http.ResponseWriter, r *http.Request)
| 821 | |
| 822 | // HandleListAPIKeys lists API keys for the authenticated user (without key values). |
| 823 | func (ua *UserAuth) HandleListAPIKeys(w http.ResponseWriter, r *http.Request) { |
| 824 | user := ua.AuthenticateRequest(r) |
| 825 | if user == nil { |
| 826 | http.Error(w, "not authenticated", http.StatusUnauthorized) |
| 827 | return |
| 828 | } |
| 829 | |
| 830 | keys, err := ua.store.ListAPIKeys(r.Context(), user.ID) |
| 831 | if err != nil { |
| 832 | http.Error(w, "failed to list API keys", http.StatusInternalServerError) |
| 833 | return |
| 834 | } |
| 835 | if keys == nil { |
| 836 | keys = []identity.APIKey{} |
| 837 | } |
| 838 | |
| 839 | w.Header().Set("Content-Type", "application/json") |
| 840 | writeJSON(w, keys) |
| 841 | } |
| 842 | |
| 843 | // HandleDeleteAPIKey deletes an API key owned by the authenticated user. |
| 844 | func (ua *UserAuth) HandleDeleteAPIKey(w http.ResponseWriter, r *http.Request) { |