Malformed auth code

11,000 views
Skip to first unread message

Oliver

unread,
Mar 12, 2022, 2:00:33 PM3/12/22
to Google Ads API and AdWords API Forum
Hi,

Please note, I previously had an issue getting the refresh token, which I posted about here:

This thread is about a different issue, with a different error.

I've been getting refresh tokens successfully but today I'm getting a "Malformed auth code" error.

Visiting the request URL works fine as evidenced by the output in the browser:

Authorization code was successfully retrieved.
Please check the console output.

But, instead of displaying the token, the terminal shows the following error:

Traceback (most recent call last):
  File "/home/.../authenticate_in_web_application.py", line 206, in <module>
    main(args.client_secrets_path, configured_scopes)
  File "/home/.../authenticate_in_web_application.py", line 84, in main
    flow.fetch_token(code=code)
  File "/home/.../.local/lib/python3.9/site-packages/google_auth_oauthlib/flow.py", line 286, in fetch_token
    return self.oauth2session.fetch_token(self.client_config["token_uri"], **kwargs)
  File "/home/.../.local/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 366, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "/home/.../anaconda3/envs/backstop/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 448, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "/home/.../anaconda3/envs/backstop/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response
    validate_token_parameters(params)
  File "/home/.../anaconda3/envs/backstop/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 448, in validate_token_parameters
    raise_from_error(params.get('error'), params)
  File "/home/.../anaconda3/envs/backstop/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 399, in raise_from_error
    raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Malformed auth code.

Has anyone else encountered this? Thanks in advance for looking! :)

Google Ads API Forum Advisor

unread,
Mar 13, 2022, 9:30:00 PM3/13/22
to oliver...@hallam.co.uk, adwor...@googlegroups.com
Hi Oliver,

Thank you for posting your concern.

The invalid_grant (Malformed auth code) error occurs when attempting to generate a refresh token for a user that has already granted access to the requesting application. For example, this can happen when running the Authenticate in Web Application example more than once for the same OAuth client credentials and authorizing user.

With this, in order to regenerate a refresh token for a given combination of authorizing user and OAuth client credentials, follow these instructions to revoke an existing refresh token. Note that revoking a token will render it unusable for Google Ads API access, and will invalidate any access tokens that the refresh token was used to generate.

Furthermore, make sure to store your refresh token in a secure location to avoid the need for regeneration.

Regards,
Google Logo
Ernie John
Google Ads API Team
 


ref:_00D1U1174p._5004Q2Ykk1q:ref

Ngon Nguyen

unread,
Mar 17, 2022, 8:42:29 PM3/17/22
to Oliver Fokerd, Google Ads API and AdWords API Forum
Chào mừng bạn đến với bảng nhớ tạm của Gboard, bất kỳ văn bản nào bạn sao chép sẽ được lưu tại đây.Sử dụng biểu tượng chỉnh sửa để ghim, thêm hoặc xóa đoạn.Nhấn vào một đoạn để dán vào hộp văn bản.Chạm và giữ một đoạn để ghim đoạn đó. Các đoạn đã bỏ ghim sẽ bị xóa sau 1 giờ.

Vào 2:00, CN, 13 thg 3, 2022 Oliver <oliver...@hallam.co.uk> đã viết:
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/70fe79da-c978-48af-a677-4e8671386761n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages