rlittlefield / pypaseto

PASETO for Python
Other
96 stars 11 forks source link

Empty exception when parsing Go paseto v2 public #16

Open hazcod opened 3 years ago

hazcod commented 3 years ago

Hi! Thank you for the library.

I am trying to parse a public (v2) paseto token generated by https://github.com/o1egl/paseto . However, an empty exception is returned when parsing.

        try:
            parsed = paseto.parse(
                key=self.tokenSecretKey,
                purpose='local',
                token=tokenValue,
                encoder=paseto.JsonEncoder, 
                validate=False,
                rules=None,
                required_claims=[
                    '1',
                    '2',
                    '3',
                ]
            )
        except Exception as e:
            raise ValueError("token decrypt failed: " + str(e))

Returns: token decrypt failed:.

Generator:

            now := time.Now()
                        pasetoV2 := paseto.NewV2()
            jsonToken := paseto.JSONToken{
                Audience:   "",
                Subject:    "",
                Issuer:     "foo",
                Jti:        strconv.FormatUint(ID, 10),
                Expiration: now.AddDate(0, 0, tokenExpiryDays),
                IssuedAt:   now,
                NotBefore:  now,
            }

            jsonToken.Set("1", testUUID)
            jsonToken.Set("2", strconv.FormatUint(ID, 10))
            jsonToken.Set("3", user.Name)

            token, err := pasetoV2.Encrypt(cryptoKeyBytes, jsonToken, nil)
            if err != nil { ... }
rlittlefield commented 2 years ago

If you have a public token, try passing in purpose='public' to the paseto.parse call. If you pass "local", it will be expecting a local type token.

rlittlefield commented 2 years ago

Not sure if you had any luck with this. I'm guessing this is because we don't have messages for some of these exceptions.

I've added this issue to track this: https://github.com/rlittlefield/pypaseto/issues/18

If you are having trouble figuring out which exception before I get a fix in for this, you can to str(type(e)), which should give you the name of the exception class.