Skip to content

Commit 8210acf

Browse files
sfc-gh-pbulawasfc-gh-mkellersfc-gh-mhofman
authored
SNOW-1917265: Add OAUTH_TYPE for authorization flow (#2174)
Co-authored-by: Mark Keller <[email protected]> Co-authored-by: Michał Hofman <[email protected]>
1 parent 3fbb1ed commit 8210acf

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/snowflake/connector/auth/oauth_code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import urllib3
1818

1919
from ..compat import parse_qs, urlparse, urlsplit
20+
from ..constants import OAUTH_TYPE_AUTHORIZATION_CODE
2021
from ..errorcode import (
2122
ER_IDP_CONNECTION_ERROR,
2223
ER_OAUTH_STATE_CHANGED,
@@ -92,6 +93,7 @@ def update_body(self, body: dict[Any, Any]) -> None:
9293
"""
9394
body["data"]["AUTHENTICATOR"] = OAUTH_AUTHENTICATOR
9495
body["data"]["TOKEN"] = self._oauth_token
96+
body["data"]["OAUTH_TYPE"] = OAUTH_TYPE_AUTHORIZATION_CODE
9597

9698
def construct_url(self) -> str:
9799
params = {

src/snowflake/connector/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,4 @@ class IterUnit(Enum):
436436
)
437437

438438
_OAUTH_DEFAULT_SCOPE = "session:role:{role}"
439+
OAUTH_TYPE_AUTHORIZATION_CODE = "authorization_code"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
4+
#
5+
6+
from snowflake.connector.auth import AuthByOauthCode
7+
8+
9+
def test_auth_oauth_auth_code_oauth_type():
10+
"""Simple OAuth Auth Code oauth type test."""
11+
auth = AuthByOauthCode(
12+
"app",
13+
"clientId",
14+
"clientSecret",
15+
"auth_url",
16+
"tokenRequestUrl",
17+
"redirectUri:{port}",
18+
"scope",
19+
)
20+
body = {"data": {}}
21+
auth.update_body(body)
22+
assert body["data"]["OAUTH_TYPE"] == "authorization_code"

0 commit comments

Comments
 (0)