Skip to content

Commit

Permalink
write auth for farcaster and lens
Browse files Browse the repository at this point in the history
  • Loading branch information
benny-conn committed Oct 24, 2023
1 parent c355c6d commit fa2adb1
Show file tree
Hide file tree
Showing 19 changed files with 448 additions and 27 deletions.
4 changes: 3 additions & 1 deletion autosocial/autosocial.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func CoreInitServer(ctx context.Context) *gin.Engine {
pgx := postgres.NewPgxClient()
queries := coredb.New(pgx)

ney := farcaster.NewNeynarAPI(http.DefaultClient)
router.Use(middleware.GinContextToContext(), middleware.Sentry(true), middleware.Tracing(), middleware.HandleCORS(), middleware.ErrLogger())
router.POST("/process/users", processUsers(queries, farcaster.NewNeynarAPI(http.DefaultClient), lens.NewAPI(http.DefaultClient)))
router.POST("/process/users", processUsers(queries, ney, lens.NewAPI(http.DefaultClient)))
router.GET("/checkFarcasterApproval", checkFarcasterApproval(queries, ney))
return router
}

Expand Down
43 changes: 43 additions & 0 deletions autosocial/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,49 @@ func processUsers(q *coredb.Queries, n *farcaster.NeynarAPI, l *lens.LensAPI) gi
}
}

func checkFarcasterApproval(q *coredb.Queries, n *farcaster.NeynarAPI) gin.HandlerFunc {
return func(c *gin.Context) {
var in task.AutosocialPollFarcasterMessage
if err := c.ShouldBindQuery(&in); err != nil {
util.ErrResponse(c, http.StatusBadRequest, err)
return
}

s, err := n.GetSignerByUUID(c, in.SignerUUID)
if err != nil {
util.ErrResponse(c, http.StatusInternalServerError, err)
return
}

if s.Status != "approved" {
util.ErrResponse(c, http.StatusInternalServerError, err)
return
}

user, err := q.GetSocialsByUserID(c, in.UserID)
if err != nil {
util.ErrResponse(c, http.StatusInternalServerError, err)
return
}
far, ok := user[persist.SocialProviderFarcaster]
if !ok {
util.ErrResponse(c, http.StatusInternalServerError, err)
return
}

far.Metadata["signer_status"] = s.Status

err = q.AddSocialToUser(c, coredb.AddSocialToUserParams{
UserID: in.UserID,
Socials: persist.Socials{
persist.SocialProviderFarcaster: far,
},
})

c.JSON(http.StatusOK, util.SuccessResponse{Success: true})
}
}

func addLensProfileToUser(ctx context.Context, l *lens.LensAPI, address []persist.ChainAddress, q *coredb.Queries, userID persist.DBID) error {
for _, a := range address {
if a.Address() == "" {
Expand Down
2 changes: 2 additions & 0 deletions db/queries/core/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ SELECT * FROM users WHERE (traits->$1::string) IS NOT NULL AND deleted = false;
-- name: GetUsersWithTraitBatch :batchmany
SELECT * FROM users WHERE (traits->$1::string) IS NOT NULL AND deleted = false;

-- name:

-- name: GetGalleryById :one
SELECT * FROM galleries WHERE id = $1 AND deleted = false;

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ services:
'projects/gallery-local/locations/here/queues/email',
'-queue',
'projects/gallery-local/locations/here/queues/autosocial',
'-queue',
'projects/gallery-local/locations/here/queues/autosocial-poll',
]
pubsub-emulator:
image: gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators
Expand Down
12 changes: 11 additions & 1 deletion graphql/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion graphql/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion graphql/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions graphql/resolver/schema.resolvers.helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"database/sql"
"errors"
"fmt"
"golang.org/x/net/html"
"strings"
"time"

"golang.org/x/net/html"

"github.com/gammazero/workerpool"
"github.com/magiclabs/magic-admin-go/token"

Expand Down Expand Up @@ -216,7 +217,11 @@ func (r *Resolver) socialAuthMechanismToAuthenticator(ctx context.Context, m mod
}

if m.Lens != nil {
return publicapi.For(ctx).Social.NewLensAuthenticator(authedUserID, m.Lens.Address), nil
sig := ""
if m.Lens.Signature != nil {
sig = *m.Lens.Signature
}
return publicapi.For(ctx).Social.NewLensAuthenticator(authedUserID, m.Lens.Address, sig), nil
}

return nil, errNoAuthMechanismFound
Expand Down
1 change: 1 addition & 0 deletions graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,7 @@ input FarcasterAuth {

input LensAuth {
address: Address!
signature: String @scrub
# lens only supports ETH addresses currently so no need to specify a chain
}

Expand Down
3 changes: 2 additions & 1 deletion publicapi/socials.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ func (s SocialAPI) NewFarcasterAuthenticator(userID persist.DBID, address persis
}
}

func (s SocialAPI) NewLensAuthenticator(userID persist.DBID, address persist.Address) *socialauth.LensAuthenticator {
func (s SocialAPI) NewLensAuthenticator(userID persist.DBID, address persist.Address, sig string) *socialauth.LensAuthenticator {
return &socialauth.LensAuthenticator{
HTTPClient: s.httpClient,
UserID: userID,
Queries: s.queries,
Address: address,
Signature: sig,
}
}

Expand Down
5 changes: 3 additions & 2 deletions secrets/dev/backend-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ GCLOUD_USER_PREF_BUCKET: ENC[AES256_GCM,data:xRr1aKffotk+aaqjCQ==,iv:SWp8vm2Tb5G
EMAILS_QUEUE: ENC[AES256_GCM,data:ZOUviMU+qtyGcHYbuVagc5vYzbATV1wRm9YBLzKWQdTnQeTQJeQ1+n8KUZZSeeWzJgazgv/ZpkdR/sY=,iv:TXo6iW9hneOMTTHUJJkBh7t9PpEoA778tVPfDmLxll8=,tag:iO7RJDNjUguvsEkC8TFUvA==,type:str]
EMAILS_TASK_SECRET: ENC[AES256_GCM,data:bOV1Bp1WidXFGkprWGZl1cr8zRuz2YlVZ9jIlx5lBaE=,iv:VAmyf21miDHuwWqXbe/fVNA7Nk43Q+F2y9zroE7qB6w=,tag:6ervW0J9B6YLEQPLkNDuXw==,type:str]
AUTOSOCIAL_QUEUE: ENC[AES256_GCM,data:Drwp2QJvFRGleEfhCwcqcUIWmiGE03QHhDfDitWhrBq/dCjHGYww26u4YJRrg344nAU254EUb+rmsH5qXEgzyg==,iv:J63wP8pIDHyqbHoPJR14npxg8gplZ0ztScBsuAP4D+k=,tag:OJzAdrI+VMjBvbAm3TKXLA==,type:str]
AUTOSOCIAL_POLL_QUEUE: ENC[AES256_GCM,data:5FQ4Ffp8cWbiGfbEEjn1zblBddof7+oTbRAbYx30EUPGCt11aIWKKGkLB7AM4mSgl7ln91b8BFqhJJ9Cg+60ACyL5q3j,iv:abJBRMtaGRdsy72O+8795bfu+EK7YXEKy9E2Ejjzzn4=,tag:i6APKPkF9RNPhRXyIwGduQ==,type:str]
AUTOSOCIAL_URL: ENC[AES256_GCM,data:4t2yAxgNVw42WqeSzHiXcITANTHSWQIh9TsEGW62xBnhFsizxfbh7UsW,iv:oW4x0ydvjTXk7lkNfhCscY4tYZJhyxXHzIo33C+IMCo=,tag:R3aZ3bDpB/wjbzRPRBgFCg==,type:str]
sops:
kms: []
Expand All @@ -85,8 +86,8 @@ sops:
azure_kv: []
hc_vault: []
age: []
lastmodified: "2023-10-03T19:45:45Z"
mac: ENC[AES256_GCM,data:3RdMYUN9gFoKvvpUFakn0Dp1nOWunFswVvw3CIeCunbp5mKU+gbS1ohOmNtbyBc3xE3kzU6AUBP36rr9fK3s5Gzj2JK8XDpEcXfkWnFJInIyVo3ClwjjNIRuqwVRysAaoLZ1GAQvq5XZ1modayCWQkrnkTf+cBAudSuweH3XF/w=,iv:Z1RM027rrzbnO73pxJPK4VTaImZ5Ce6Xcslc/EYWD3w=,tag:QDNwaBXeKa2wRYqqu0SLrg==,type:str]
lastmodified: "2023-10-24T06:26:41Z"
mac: ENC[AES256_GCM,data:cTzTvWf4Etmq95FHSLGjNCNSPiq+0wWmkLzXm6o5UkX0JD7ZXn8iEz5JmVhlWZYYweBLfSdFCRyxpBvvpCYOvWKivMHxnUIL0pup/eCcawu9iV4eN2HO8P7FYA2BqTIR4r+SpPfavc1r+ZePCi8uFlMw2Zs8iAIAGphu7elprN0=,iv:rrDBWe1KPl/XvM2XvpyBPdujoQ1Ej60IlYe70aDp6F0=,tag:xHqfx6SUiXC2koqITEYHKQ==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.7.3
5 changes: 3 additions & 2 deletions secrets/dev/local/app-dev-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ EMAILS_QUEUE: ENC[AES256_GCM,data:alOYj1WuVvGjetBCFtFhN2NqmdxDifbxHCUNw2TkSGhD14
EMAILS_TASK_SECRET: ENC[AES256_GCM,data:s27svCF9CtqvDddlkqpbpchN/TKXRLTK3fs1IuIF2FQ=,iv:OrzkHkUFK0r6UPb7IZkmTqtxRlsilAQ4OUK8YRLjqg8=,tag:he3wH/Nsv8NEDYDV0FlgPw==,type:str]
AUTOSOCIAL_QUEUE: ENC[AES256_GCM,data:+BTIQbwpXJudqIX9MRHOOoqHyoJxzGi+RWpIwVZIb3AnXixQUsDMgLK68VHiuLbJRbs39b1X1Q==,iv:LOw/wc6qZNildKhwzgHa1plpGwF80e/3vCMWcemMAoU=,tag:F7HZ2tn3c45SmyqBWV/JZg==,type:str]
AUTOSOCIAL_URL: ENC[AES256_GCM,data:2B6jfL92LdHhuWRpI/o=,iv:kJr//brJh3Thno9FHbkyEgJh9HQ4vMkLP26c8Lcnxbc=,tag:QLsaigs+YowjgMtLLIm69w==,type:str]
AUTOSOCIAL_POLL_QUEUE: ENC[AES256_GCM,data:KoTHV1WcXWiZl9AH1N9hFbLPKcLJtu6t7VU1AOxVIrZKz3OB2Ml3YYFLNYjQmJJuZp6vcZJcgxgOG/VO,iv:QFiI0UR6FAIp8fqdb4/8Vg+V6XV6dytriQ/aw82dBKw=,tag:6wHxd0XoYD2jPIolgDWaqQ==,type:str]
FEEDBOT_URL: ENC[AES256_GCM,data:381swg3qLYO6UfGdWz65pwv6dnC3MrD4hrcYHrvfq3lKF/ySAAkH3/IKwg==,iv:n06Bc+VsJZKvV9RZAqxlGL8+EqboXdBOHbR8xqv4G8I=,tag:0ZjRuTOGrR4D+fQ49/2hYw==,type:str]
sops:
kms: []
Expand All @@ -59,8 +60,8 @@ sops:
azure_kv: []
hc_vault: []
age: []
lastmodified: "2023-10-03T19:45:47Z"
mac: ENC[AES256_GCM,data:iPjrLuzM1d0dWIdLU9shrYhHy3Tlwez5Ia7GwrW3pTUeOvduNku9wEqH8MsDKjuPk8ezt/QmR+78J0tXKHLOSWzV9BhULYIv2DZtxBwPbxkVOyebb7rD0X/7/6ZjpBbWI2TNtIhXEt070mF9K1HBdTZB8ZsWUHmrlaMeShduo4Y=,iv:09xzk/dcBVQD96ZFSKzsi8FfK7PV2zxs0M1qkSTQjdI=,tag:7aZyKrlanqUahv/GiYuOTw==,type:str]
lastmodified: "2023-10-24T06:26:57Z"
mac: ENC[AES256_GCM,data:e9WQ5c7hWO3rURwD331M+pVcuRuFMdFKBTN8jcaXXT7rgeXkwPEO9L/lqKWL64nl+L0/N/7RIoV4zmG5/9Xk2Gw+yayTWBA4H7iK7Y0WhOLCVldOynCRAfrDowzL5L+EPFl8q+LR6J5jp39OiFVNzOTh+E/89KBKsdBgenWdbM0=,iv:rIdnpM7Tzx2cLC8OwahIJ1be44wBfL6pcTz312bKA4s=,tag:y9abCY5Z9diOciy9OlDnKw==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.7.3
5 changes: 3 additions & 2 deletions secrets/local/local/app-local-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RPC_URL: ENC[AES256_GCM,data:Qt54Eru5hohZXpV2pUCx/0+dg7CpVK7bHYEGye/fej+WV2HxjGo
GCLOUD_USER_PREF_BUCKET: ENC[AES256_GCM,data:+abxLn4GAtNR/PRAjg==,iv:pywnL1YJzPfgEyHVvCJeJc83WaScMhL81QNCJasTzac=,tag:+91RyaN4clWzmXURuXqxMA==,type:str]
EMAIL_QUEUE: ENC[AES256_GCM,data:DZlQknhz+9UvLcin3j4iamhRp4y0ZrsRmcuhEArrXtBro1b58ov6T1PnSHw43pUgc5c=,iv:KrJQSR1FnwVA9Ue0cJTzqmLwz7DG/dF8LvI1aNWMic4=,tag:Bba+2d2hH3vaABLqPc1knQ==,type:str]
AUTOSOCIAL_QUEUE: ENC[AES256_GCM,data:VPxQ8izFihl26rbrTe/sBgb3x+IvIobtPWKcDTUGuqAXlwgT4LNxVs4biB3fsP02nsJ7Z5SKug==,iv:CzPRmkSIt6rxkQ9GmWQl1UEbFTnuKZzqO92Jp+gf3MI=,tag:sFqz7HLDHc/6+CFDJZSJLg==,type:str]
AUTOSOCIAL_POLL_QUEUE: ENC[AES256_GCM,data:lJcSmOd4k8zk09H4tS6LpC3dv9o3xWb4syW7ITnuFZpAry1V0c0KzV8McaLx1L7MQNYwC8s3nuUZTM5y,iv:wB0H3kHl0kofMe/TE25czNrlCekGgPfZhxjhs3KtDJ8=,tag:K7RixYUmheMYn3FakPZhoA==,type:str]
AUTOSOCIAL_URL: ENC[AES256_GCM,data:Jx2v/E4x841LeDjmiUUmTT70IBfJmmzbhmCUTd/aqUM=,iv:n8NkhZosTCwo0AEXuRvQoVvlzBcEdWa1Swa2gWIA8yU=,tag:BH5wARsJ4w31HFkVfMBN7w==,type:str]
sops:
kms: []
Expand All @@ -53,8 +54,8 @@ sops:
azure_kv: []
hc_vault: []
age: []
lastmodified: "2023-10-23T18:41:58Z"
mac: ENC[AES256_GCM,data:8BrdTVeD9/Gb4YZF8ds94zTFb1UrU/eCtZ4POBUJYdYLgddFCXezomJQNr0QJrOI/pAc6ObKa31yuVpZTkYGc9yC6uNMWF+oVMdtzlJkXuRIG6zlBmaBGZr0MIWWk3P5RY6zGGpBIHbHTCIFrMscXRxIizss63XxTzIsqPTpev8=,iv:epX4hH8qJWhDtSdIfhD2IeLIZUPf8/LrPJPpe9p6Wng=,tag:y31wz30w9UDBgaeub9VW6Q==,type:str]
lastmodified: "2023-10-24T06:25:40Z"
mac: ENC[AES256_GCM,data:vr+FisofpJ5WdBcMd+S+1BD31VPjZ5PYEmZfkXwZkKUdYrpAPGR48hmQBlJuMh33CbWUNipJuTmHSWyCpcu1LEkXwZvev2WZ8stHhNFpPWSBU5C9iW682w0Uel8UolGvzFY9F0+NkF/H3o5ZoeMwMePvnVEoQFpnqUoPpdc8Z+M=,iv:A4Et5/ud0IJCxnbCXRAqyZ9VD39LvKfSsSk4K7zHLnU=,tag:Pn/BUpc4ScvIafcKvi7tAQ==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.7.3
5 changes: 3 additions & 2 deletions secrets/prod/backend-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GOLDSKY_API_KEY: ENC[AES256_GCM,data:Cof9gRBnQ3OXV8Fo+aJhv7J34tgd/KyNQA==,iv:5CB
GCLOUD_USER_PREF_BUCKET: ENC[AES256_GCM,data:d30SUr/1z/8u0XPCgb8=,iv:xKanYFb0ySLhZu0vrTcBycAqMuQb+RsSw5x/lwhYmTM=,tag:0rXKTpz2DUQkB1cacv906Q==,type:str]
EMAILS_QUEUE: ENC[AES256_GCM,data:DxWePlmNdmVaDnV+qtNuoQl5OT2r9oFSwZGO0C19Ra4HhZm9ySl4dhZ+0kpB40dsO61A43WzrWFuRbYK,iv:djCFFuJflxrulIHxE5AEpTgqVcQEHWvnQzP0z6vH0Yc=,tag:4mAAor7FKQfcpHhHBvjPzg==,type:str]
AUTOSOCIAL_QUEUE: ENC[AES256_GCM,data:pOl1MmNzmzLkmVDfDL/ZXAX8mKIV2p/E25OKh46YdVSb4Ve0u4dPlGumJgWkpC9fFSCLRbCKMShwIOre+itrsv0=,iv:aLUhiFzmx2a8f577xT1G0mFlBFBttY1JoZsy2w0Ozzs=,tag:YEtSVNNEXQ08TZJxos/vXA==,type:str]
AUTOSOCIAL_POLL_QUEUE: ENC[AES256_GCM,data:JaRosMbk8lh5si61XYU/w/g/fTdIJgy5wDLeqtNqszW4fxVHleU88QTAWHwKpRjpe+adkNLyWFu/0JX0snLSy47cDkj6kw==,iv:EPFzS58+dfzs9dLFI4tsrVFIaxoQvmtvN/tQEcO6OBI=,tag:jEfm/XczkJXGDS/wgKJbaw==,type:str]
AUTOSOCIAL_URL: ENC[AES256_GCM,data:1++2NVhPw2K6vfAJO/DYX6w+OeieJQKC7X/+yQOJ655d+wtrz+HGq713,iv:BS+dpFcn5G4WxbEG1C3sz2NSb5ro5LkLkgEkPJA8gyc=,tag:Gcg/lXOTJiAf0EkiM9TN8g==,type:str]
EMAILS_TASK_SECRET: ENC[AES256_GCM,data:C+HWjJa5qu5Rs2xGjqek6tcYI8SnGhdziOSyq54W7Uk=,iv:qcek1g7fyDb3B8mOrDqowoYXGvS6WkAyuN9xABGkZfw=,tag:qvlHiesFIvUe8Il3INXzkQ==,type:str]
sops:
Expand All @@ -85,8 +86,8 @@ sops:
azure_kv: []
hc_vault: []
age: []
lastmodified: "2023-10-03T19:45:31Z"
mac: ENC[AES256_GCM,data:eM9VBYmr3icW5Pege444uYbWUOkzOmUMqZvStS/BqTlymvrg1AM4QMvJ+hVHEmlxSaxmhl0MAZ1LfoVRXCg3Yvwcyd8tg8k/W4qHmiXC7ltXWPiz0SEld9OPyzsuAxUOIfXiyEXHREDvwrqPkj7usVAmJiKN9tkjPTcYLvzDnRs=,iv:UGl2y0iT2iW2wXDGIPJPe80mI2JlQ9ICcUA6VUyRzRM=,tag:yxPCz1owqswnFFGN2IlOFw==,type:str]
lastmodified: "2023-10-24T06:26:12Z"
mac: ENC[AES256_GCM,data:fkA3vYODXXy+syViPfWE2yabvZ5tGFdiQIQQOukqUtlOnaTd8qYv03BDnjwrpGGKFtUp8WS1emTHEVdVU6WsSw34EmCSMRhfP92AXteYw3c7cmWjiiOVMZVwf0lCtHhcaP8nsiKWSUYPcACa5SDfbEr0QWt5Vsf+pEiKnPrkPQQ=,iv:eTOo82Rj6t8cHSi/MbYRFBiWY3BDSBZLpJt/SL6rV/w=,tag:NWJtvy6sRefgUqKzf4//ug==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.7.3
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ func SetDefaults() {
viper.SetDefault("EMAILS_TASK_SECRET", "emails-task-secret")
viper.SetDefault("AUTOSOCIAL_URL", "")
viper.SetDefault("AUTOSOCIAL_QUEUE", "")
viper.SetDefault("AUTOSOCIAL_POLL_QUEUE", "")
viper.SetDefault("FARCASTER_PRIVATE_KEY", "")
viper.SetDefault("FARCASTER_APP_ID", "")

viper.AutomaticEnv()

Expand Down
Loading

0 comments on commit fa2adb1

Please sign in to comment.