Delete records and stuff

This commit is contained in:
2026-02-12 11:43:52 -06:00
parent 200cb59b0e
commit 009d5701d2
6 changed files with 303 additions and 140 deletions

View File

@@ -26,6 +26,7 @@ type AuthRepo struct {
context context.Context
session *oauth.ClientSessionData
authUrl string
authError error
Logger *slog.Logger
@@ -58,6 +59,7 @@ func (r *AuthRepo) buildOAuthClient() (*oauth.ClientConfig, *oauth.ClientApp, *S
SessionExpiryDuration: time.Hour * 24 * 90,
SessionInactivityDuration: time.Hour * 24 * 14,
AuthRequestExpiryDuration: time.Minute * 30,
Logger: r.Logger,
})
if err != nil {
return nil, nil, nil, err
@@ -68,19 +70,20 @@ func (r *AuthRepo) buildOAuthClient() (*oauth.ClientConfig, *oauth.ClientApp, *S
}
func (r *AuthRepo) StartAuthFlow(port int, identifier string, callbackRes chan url.Values) (string, error) {
var err error
r.oauthConfig.CallbackURL = fmt.Sprintf("http://127.0.0.1:%d/callback", port)
authUrl, err := r.oauthClient.StartAuthFlow(r.context, identifier)
r.authUrl, err = r.oauthClient.StartAuthFlow(r.context, identifier)
if err != nil {
return "", fmt.Errorf("error logging in: %w", err)
}
if !strings.HasPrefix(authUrl, "https://") {
if !strings.HasPrefix(r.authUrl, "https://") {
return "", fmt.Errorf("non-https authUrl")
}
go func() {
exec.Command("xdg-open", authUrl).Start()
exec.Command("xdg-open", r.authUrl).Start()
r.session, r.authError = r.oauthClient.ProcessCallback(r.context, <-callbackRes)
}()
return authUrl, nil
return r.authUrl, nil
}
// Follows XDG conventions and creates the directories if necessary.
@@ -101,6 +104,12 @@ func (r *AuthRepo) ListenForCallback(res chan url.Values) (int, error) {
Handler: mux,
}
mux.HandleFunc("/auth", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Location", r.authUrl)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(303)
})
mux.HandleFunc("/callback", func(w http.ResponseWriter, req *http.Request) {
res <- req.URL.Query()
w.Header().Set("Content-Type", "text/html; charset=utf-8")
@@ -130,6 +139,6 @@ func (r *AuthRepo) GetSession(did syntax.DID) (*oauth.ClientSession, error) {
if err != nil {
return nil, fmt.Errorf("error getting most recent session: %w", err)
}
r.Logger.Warn(fmt.Sprintf("GetSession(): Resuming Session: %s (%s)", sess.SessionID, sess.AccountDID))
r.Logger.Debug(fmt.Sprintf("GetSession(): Resuming Session: %s (%s)", sess.SessionID, sess.AccountDID))
return r.oauthClient.ResumeSession(r.context, sess.AccountDID, sess.SessionID)
}