0

GDrive OAuth allows for a state parameter to be passed from the request to the response callback. When I send a string that contains a single token, it works as expected, but if I send a json, then I can't seem to read back the value from the state parameter in the callback function.

I have tried using base64.encodestring(), base64.urlsafe_b64encode() and the decode versions of the these functions in the callback but then I get an "Incorrect Padding" error on decode.

To correct this, I tried the following snippet I found on StackOverflow:

`stateStr += "=" * ((4 - len(stateStr) % 4) % 4)`
`stateList = base64.urlsafe_b64decode(stateStr)`

But I still get the "Incorrect Padding" error.

Any help will be appreciated,

Thanks

EDIT The workaround to this problem was for me to separate the strings by using a '|' char. That way I'm still passing a single string which works fine without any padding errors. EDIT

bhanu
  • 33
  • 1
  • 4

1 Answers1

0

Based from this SO post, there are various ways in which base64 data could be corrupted. It was stated here that the padding character is not needed, since the number of missing bytes can be calculated from the number of Base64 digits.

If there's a padding error it probably means your string is corrupted; base64-encoded strings should have a multiple of four length. You can try adding the padding character (=) yourself to make the string a multiple of four, but it should already have that unless something is wrong.

abielita
  • 13,147
  • 2
  • 17
  • 59