Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temporary workaround for server.GetSession #225

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"connectrpc.com/connect"
"github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/xrpc"
"github.com/strideynet/bsky-furry-feed/bluesky"
v1 "github.com/strideynet/bsky-furry-feed/proto/bff/v1"
Expand All @@ -25,7 +24,7 @@ func BSkyTokenValidator(pdsHost string) func(ctx context.Context, token string)
// parse the JWT as they do not use public key signing for the JWT.
return func(ctx context.Context, token string) (did string, err error) {
ua := bluesky.UserAgent
res, err := atproto.ServerGetSession(ctx, &xrpc.Client{
res, err := getBlueskySession(ctx, &xrpc.Client{
Host: pdsHost,
UserAgent: &ua,
Auth: &xrpc.AuthInfo{AccessJwt: token},
Expand All @@ -37,6 +36,23 @@ func BSkyTokenValidator(pdsHost string) func(ctx context.Context, token string)
}
}

type ServerGetSession_Output struct {
Did string `json:"did" cborgen:"did"`
Email *string `json:"email,omitempty" cborgen:"email,omitempty"`
EmailConfirmed *bool `json:"emailConfirmed,omitempty" cborgen:"emailConfirmed,omitempty"`
Handle string `json:"handle" cborgen:"handle"`
}

// Workaround until Bluesky’s util.LexiconTypeDecoder for
// DidDoc doesn’t always error with `unrecognized type: ""`
func getBlueskySession(ctx context.Context, c *xrpc.Client) (*ServerGetSession_Output, error) {
var out ServerGetSession_Output
if err := c.Do(ctx, xrpc.Query, "", "com.atproto.server.getSession", nil, nil, &out); err != nil {
return nil, err
}
return &out, nil
}

// authenticatedUserPermissions are granted to any user who is authenticated.
var authenticatedUserPermissions = []string{
"/bff.v1.ModerationService/Ping",
Expand Down