Skip to content

Commit

Permalink
Fix GA_KEY_CONTENT OpenSSL crypto error
Browse files Browse the repository at this point in the history
OpenSSL.crypto.load_privatekey can't detect start line due to a
str.replace() for '\n' and '\r'.
json.loads() can't handle '\n' and '\r' cause it thinks they are
control character.
Therefore '\n' and '\r' have to be double escape rather than deleted.
OpenSSL.crypto.load_privatekey() can't handle '\r' either,
so a private_key with '\r' wouldn't work anyway. ¯\_(ツ)_/¯

Error:
OpenSSL.crypto.Error: [('PEM routines', 'get_name', 'no start line')]

Ref:
tomdyson#25
https://stackoverflow.com/a/45571017
  • Loading branch information
kleberbaum committed Apr 30, 2020
1 parent 11e7962 commit fee48c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion wagalytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_access_token_from_str(ga_key_content):
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'

# Construct a credentials objects from the key data and OAuth2 scope.
keyDict = json.loads(ga_key_content.replace('\n', '').replace('\r', ''))
keyDict = json.loads(ga_key_content.replace('\n', '\\n'))
_credentials = ServiceAccountCredentials.from_json_keyfile_dict(
keyDict, SCOPE)

Expand Down

0 comments on commit fee48c1

Please sign in to comment.