···
-
comatproto "github.com/bluesky-social/indigo/api/atproto"
-
"github.com/bluesky-social/indigo/atproto/identity"
-
"github.com/bluesky-social/indigo/xrpc"
-
"github.com/gorilla/sessions"
-
"tangled.sh/tangled.sh/core/appview"
-
Store *sessions.CookieStore
-
type AtSessionCreate struct {
-
comatproto.ServerCreateSession_Output
-
type AtSessionRefresh struct {
-
comatproto.ServerRefreshSession_Output
-
func Make(secret string) (*Auth, error) {
-
store := sessions.NewCookieStore([]byte(secret))
-
return &Auth{store}, nil
-
func (a *Auth) CreateInitialSession(ctx context.Context, resolved *identity.Identity, appPassword string) (*comatproto.ServerCreateSession_Output, error) {
-
pdsUrl := resolved.PDSEndpoint()
-
atSession, err := comatproto.ServerCreateSession(ctx, &client, &comatproto.ServerCreateSession_Input{
-
Identifier: resolved.DID.String(),
-
return nil, fmt.Errorf("invalid app password")
-
// Sessionish is an interface that provides access to the common fields of both types.
-
type Sessionish interface {
-
GetDidDoc() *interface{}
-
// Create a wrapper type for ServerRefreshSession_Output
-
type RefreshSessionWrapper struct {
-
*comatproto.ServerRefreshSession_Output
-
func (s *RefreshSessionWrapper) GetAccessJwt() string {
-
func (s *RefreshSessionWrapper) GetActive() *bool {
-
func (s *RefreshSessionWrapper) GetDid() string {
-
func (s *RefreshSessionWrapper) GetDidDoc() *interface{} {
-
func (s *RefreshSessionWrapper) GetHandle() string {
-
func (s *RefreshSessionWrapper) GetRefreshJwt() string {
-
func (s *RefreshSessionWrapper) GetStatus() *string {
-
// Create a wrapper type for ServerRefreshSession_Output
-
type CreateSessionWrapper struct {
-
*comatproto.ServerCreateSession_Output
-
func (s *CreateSessionWrapper) GetAccessJwt() string {
-
func (s *CreateSessionWrapper) GetActive() *bool {
-
func (s *CreateSessionWrapper) GetDid() string {
-
func (s *CreateSessionWrapper) GetDidDoc() *interface{} {
-
func (s *CreateSessionWrapper) GetHandle() string {
-
func (s *CreateSessionWrapper) GetRefreshJwt() string {
-
func (s *CreateSessionWrapper) GetStatus() *string {
-
func (a *Auth) ClearSession(r *http.Request, w http.ResponseWriter) error {
-
clientSession, err := a.Store.Get(r, appview.SessionName)
-
return fmt.Errorf("invalid session", err)
-
if clientSession.IsNew {
-
return fmt.Errorf("invalid session")
-
clientSession.Options.MaxAge = -1
-
return clientSession.Save(r, w)
-
func (a *Auth) StoreSession(r *http.Request, w http.ResponseWriter, atSessionish Sessionish, pdsEndpoint string) error {
-
clientSession, _ := a.Store.Get(r, appview.SessionName)
-
clientSession.Values[appview.SessionHandle] = atSessionish.GetHandle()
-
clientSession.Values[appview.SessionDid] = atSessionish.GetDid()
-
clientSession.Values[appview.SessionPds] = pdsEndpoint
-
clientSession.Values[appview.SessionAccessJwt] = atSessionish.GetAccessJwt()
-
clientSession.Values[appview.SessionRefreshJwt] = atSessionish.GetRefreshJwt()
-
clientSession.Values[appview.SessionExpiry] = time.Now().Add(time.Minute * 15).Format(time.RFC3339)
-
clientSession.Values[appview.SessionAuthenticated] = true
-
return clientSession.Save(r, w)
-
func (a *Auth) AuthorizedClient(r *http.Request) (*xrpc.Client, error) {
-
clientSession, err := a.Store.Get(r, "appview-session")
-
if err != nil || clientSession.IsNew {
-
did := clientSession.Values["did"].(string)
-
pdsUrl := clientSession.Values["pds"].(string)
-
accessJwt := clientSession.Values["accessJwt"].(string)
-
refreshJwt := clientSession.Values["refreshJwt"].(string)
-
client := &xrpc.Client{
-
RefreshJwt: refreshJwt,
-
func (a *Auth) GetSession(r *http.Request) (*sessions.Session, error) {
-
return a.Store.Get(r, appview.SessionName)
-
func (a *Auth) GetDid(r *http.Request) string {
-
clientSession, err := a.Store.Get(r, appview.SessionName)
-
if err != nil || clientSession.IsNew {
-
return clientSession.Values[appview.SessionDid].(string)
-
func (a *Auth) GetHandle(r *http.Request) string {
-
clientSession, err := a.Store.Get(r, appview.SessionName)
-
if err != nil || clientSession.IsNew {
-
return clientSession.Values[appview.SessionHandle].(string)
-
func (a *Auth) GetUser(r *http.Request) *User {
-
clientSession, err := a.Store.Get(r, appview.SessionName)
-
if err != nil || clientSession.IsNew {
-
Handle: clientSession.Values[appview.SessionHandle].(string),
-
Did: clientSession.Values[appview.SessionDid].(string),
-
Pds: clientSession.Values[appview.SessionPds].(string),