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

I think merging pyjwt 2 broke things #122

Closed
athornton opened this issue Dec 18, 2023 · 7 comments
Closed

I think merging pyjwt 2 broke things #122

athornton opened this issue Dec 18, 2023 · 7 comments

Comments

@athornton
Copy link
Collaborator

  File "./giftless/view.py", line 72, in post
    response['objects'] = [action(**o) for o in payload['objects']]
  File "./giftless/view.py", line 72, in <listcomp>
    response['objects'] = [action(**o) for o in payload['objects']]
  File "./giftless/transfer/basic_external.py", line 42, in upload
    lifetime=self.VERIFY_LIFETIME)
  File "./giftless/transfer/__init__.py", line 69, in _preauth_headers
    return self._auth_module.preauth_handler.get_authz_header(identity, org, repo, actions, oid, lifetime=lifetime)
  File "./giftless/auth/jwt.py", line 127, in get_authz_header
    token = self._generate_token_for_action(*args, **kwargs)
  File "./giftless/auth/jwt.py", line 154, in _generate_token_for_action
    return self._generate_token(**token_payload).decode('ascii')
AttributeError: 'str' object has no attribute 'decode'

I wasn't getting this before. I haven't looked yet, but I see there's a new major version of pyjwt, and I strongly suspect something here changed a type from bytes[] to str. I'll take a look when I have time.

@athornton
Copy link
Collaborator Author

return jwt.encode(payload, self.private_key, algorithm=self.algorithm, headers=headers) # type: ignore

Looks very suspicious. Betting this went from bytes to str in pyjwt 2.x. We should probably get rid of the type:ignore and
do the casting properly.

@athornton
Copy link
Collaborator Author

Yep:

https://pyjwt.readthedocs.io/en/stable/changelog.html#v2-0-0

jwt.encode(...) return type

Tokens are returned as string instead of a byte string

@athornton
Copy link
Collaborator Author

And typing in pyjwt turns out to be a giant crawling can of worms. cf jpadilla/pyjwt#602

@rufuspollock
Copy link
Member

@athornton this should be fixed i guess now we merged #124. Can you confirm and then we can close this.

@athornton
Copy link
Collaborator Author

I can confirm, but not till next week (Jan. 2, 2024), when I'm back at work.

@athornton
Copy link
Collaborator Author

Oh, whoops, should have given the OK to close a while ago. This (indeed a later merge that includes this) is working fine.

@rufuspollock
Copy link
Member

FIXED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants