Skip to content

Commit 769b39f

Browse files
author
sov2000
committedDec 11, 2024
Resolving issues anitabyte#22, anitabyte#15
1 parent a8ae3e5 commit 769b39f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Python 3 client for the [Etsy Open API v3](https://developer.etsy.com/documentat
99

1010
The authorisation flow in v3 of Etsy's API is somewhat different to the flow used in v2. It is the [OAuth 2.0 Authorization Code Grant](https://www.rfc-editor.org/rfc/rfc6749#section-4.1) flow, [documented quite well by Etsy themselves](https://developer.etsy.com/documentation/essentials/authentication/). Make sure you've done the setup at `Requesting an OAuth Token`, in terms of getting your Etsy API keystring and callback URLs set up.
1111

12-
In the `etsyv3.utils.util.auth` package, the `auth_helper.py` module contains a helper class (`AuthHelper`) for the authentication flow. Provided with the keystring, one of the redirect URLs that you've specific in your Etsy app setup, a list of scopes to be provided in this authentication (a list of strings at present, but likely to become a set of `enums` in future), a code verifier string (specified by you) and a state string (also specified by you), it will allow for some simplification of the process.
12+
In the `etsyv3.util.auth` package, the `auth_helper.py` module contains a helper class (`AuthHelper`) for the authentication flow. Provided with the keystring, one of the redirect URLs that you've specific in your Etsy app setup, a list of scopes to be provided in this authentication (a list of strings at present, but likely to become a set of `enums` in future), a code verifier string (specified by you) and a state string (also specified by you), it will allow for some simplification of the process.
1313

1414
With your initialised `AuthHelper`, the flow looks something like this:
1515

‎etsyv3/util/auth/auth_helper.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import secrets
44
from typing import List, Optional, Tuple
55

6+
from etsy_api import BadRequest
67
from requests_oauthlib import OAuth2Session # type: ignore[import]
78

89

@@ -43,7 +44,8 @@ def set_authorisation_code(self, code: str, state: str) -> None:
4344
if state == self.state:
4445
self.auth_code = code
4546
else:
46-
raise
47+
# per etsy followed RFC 6749 bad state should raise invalid request, https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
48+
raise BadRequest('{"error": "invalid_request", "error_description": "State mismatch"}')
4749

4850
def get_access_token(self) -> Optional[str]:
4951
headers = {

0 commit comments

Comments
 (0)