Merge branch 'main' of ssh://git.bullercodeworks.com:2200/brian/expds

This commit is contained in:
2026-02-12 06:13:56 -06:00
10 changed files with 954 additions and 33 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"net"
"net/http"
"net/url"
@@ -13,6 +14,7 @@ import (
"time"
"github.com/bluesky-social/indigo/atproto/auth/oauth"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/spf13/viper"
)
@@ -25,12 +27,15 @@ type AuthRepo struct {
session *oauth.ClientSessionData
authError error
Logger *slog.Logger
}
func NewAuthRepo(r *Repo) (*AuthRepo, error) {
a := &AuthRepo{
r: r,
context: r.context,
Logger: r.Logger,
}
var err error
a.oauthConfig, a.oauthClient, a.store, err = a.buildOAuthClient()
@@ -109,20 +114,22 @@ func (r *AuthRepo) ListenForCallback(res chan url.Values) (int, error) {
if !errors.Is(err, http.ErrServerClosed) {
panic(err)
}
r.Logger.Debug("Server Shut Down")
}()
return listener.Addr().(*net.TCPAddr).Port, nil
}
func (r *AuthRepo) HasAuth() bool {
sess, err := r.store.GetMostRecentSession(r.context)
return err != nil || sess == nil
func (r *AuthRepo) HasAuth(did syntax.DID) bool {
sess, err := r.GetSession(did)
return err == nil && sess != nil
}
func (r *AuthRepo) GetSession() (*oauth.ClientSession, error) {
sess, err := r.store.GetMostRecentSession(r.context)
func (r *AuthRepo) GetSession(did syntax.DID) (*oauth.ClientSession, error) {
sess, err := r.store.GetMostRecentSessionFor(r.context, did)
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))
return r.oauthClient.ResumeSession(r.context, sess.AccountDID, sess.SessionID)
}