Coder Social home page Coder Social logo

algoz's People

Contributors

whyrusleeping avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

algoz's Issues

Verifying JWT

I'm trying to write some bsky go code to verify a JWT, and I'm having some issues with it validating the signature. My code looks like this:

type jwtBody struct {
	UserDID    string `json:"sub"`
	ServiceDID string `json:"aud"`
	Expiry     int64  `json:"exp,omitempty"`
}

func ValidateAuthentication(ctx context.Context, r *http.Request) error {
	authHeader := r.Header.Get("authorization")
	jwt := ""
	if strings.HasPrefix(strings.ToLower(authHeader), "bearer ") {
		jwt = authHeader[len("bearer "):]
	}

	jwtParts := strings.Split(jwt, ".")
	encodedJWTBody, jwtSignature := jwtParts[1], jwtParts[2]

	decoded, err := base64.StdEncoding.DecodeString(encodedJWTBody)
	if err != nil {
		return err
	}
	var body jwtBody
	if err = json.Unmarshal(decoded, &body); err != nil {
		return err
	}

	ignore := IgnoreJWTExpiration(ctx)
	if ignore {
		expireTime := time.Unix(body.Expiry, 0)
		if body.Expiry > 0 && time.Now().After(expireTime) {
			return errors.New("jwt expired")
		}
	}

	resolver := GetResolver(ctx)

	did, err := syntax.ParseDID(body.UserDID)
	if err != nil {
		return err
	}

	user, err := resolver.LookupDID(ctx, did)
	if err != nil {
		return err
	}

	key, err := user.PublicKey()
	if err != nil {
		return err
	}

	// rawSig, err := base64.RawStdEncoding.DecodeString(jwtSignature)
	// if err != nil {
	// 	return err
	// }

	return key.HashAndVerifyLenient([]byte(strings.Join(jwtParts[0:2], ".")), []byte(jwtSignature))
}

I was trying to look at your auth_jwt.go code and I'm having a hard time finding any uses of it. How do the signing methods in that file correlate to a JWT? I appreciate all the help you've given me (@jaygles.bsky.social) on bsky today but thought this might be a better place for it

how to run "latest from follows"?

Hi @whyrusleeping :)

I'm trying to run this code on my VPS, because I love the "Latest From Follows" feed, and would like to write a patch to the ordering (to randomize it every hour or something like that)

However I'm getting confused whether that feed lives in this repo or not, or how it works!

I do see this code that seems to generate it, I just don't see the rest of the feed metadata like description and name.

I am also a bit confused about the difference between publishing a feed's metadata, and serving the actual posts.

I am probably not auth-ing correctly either which may be contributing to the issue.

This is what i'm getting at http://137.184.28.191:3339/xrpc/app.bsky.feed.describeFeedGenerator when running the server.

(it doesn't seem to include bestoffollows!)

{"did":"","feeds":[
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/upandup"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/coolstuff"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/mostpop"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/cats"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/dogs"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/nsfw"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/seacreatures"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/flowers"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/allpics"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/allqps"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/followpics"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/cozy"},
{"uri":"at://did:plc:wmhp7mubpgafjggwvaxeozmu/app.bsky.feed.generator/enjoy"}]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.