PetterKraabol / Twitch-Python

Object-oriented Twitch API for Python developers
https://pypi.org/project/twitch-python
MIT License
214 stars 37 forks source link

Correctly strip "bearer" from bearer tokens. #22

Closed Tantusar closed 3 years ago

Tantusar commented 4 years ago

string.lstrip(str) strips from the start of string any number of characters which match the characters in str. It does not strip from the start of string the string str. The result of the current code is that if the Twitch API returns the bearer token without the word Bearer at the start (which in my experience is, in fact, the case) then any characters in the word 'Bearer' will be stripped from the start of the actual bearer token.

Given this is not the intended behaviour, this pull request proposes to instead check if the API has returned a string starting with Bearer, and if it has, to remove the first six characters from that string. This does, however, leave open a 1 in 2,176,782,336 chance that the actual bearer token starts with the characters bearer in that order, assuming this edge case isn't already filtered out by the Twitch API. Further work may be required.

sonarcloud[bot] commented 4 years ago

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information