Skip to content

Commit 1f3879f

Browse files
authored
feat: Introduce granted scopes to credentials (#257)
* feat: Introduce granted scopes to credentials * adding test * check for empty granted scope * Remove 3.6 * Remove 3.6 from requirements.txt * workaround for 3.6 * exclude unittest file from owlbot
1 parent d114a6e commit 1f3879f

7 files changed

Lines changed: 32 additions & 5 deletions

File tree

packages/google-auth-oauthlib/.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
name: unittest
66
jobs:
77
unit:
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-20.04
99
strategy:
1010
matrix:
1111
python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']

packages/google-auth-oauthlib/google_auth_oauthlib/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def credentials_from_session(session, client_config=None):
145145
client_id=client_config.get("client_id"),
146146
client_secret=client_config.get("client_secret"),
147147
scopes=session.scope,
148+
granted_scopes=session.token.get("scope"),
148149
)
149150
credentials.expiry = datetime.datetime.utcfromtimestamp(session.token["expires_at"])
150151
return credentials

packages/google-auth-oauthlib/owlbot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
)
1515
s.move(templated_files, excludes=[
1616
"docs/multiprocessing.rst",
17-
"README.rst"
17+
"README.rst",
18+
".github/workflows/unittest.yml" #remove this exclusion when removing 3.6 from unit test
1819
])
1920

2021
# Change black paths

packages/google-auth-oauthlib/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
TOOL_DEPENDENCIES = "click>=6.0.0"
2222

23-
DEPENDENCIES = ("google-auth>=2.14.0", "requests-oauthlib>=0.7.0")
23+
DEPENDENCIES = ("google-auth>=2.15.0", "requests-oauthlib>=0.7.0")
2424

2525

2626
with io.open("README.rst", "r") as fh:

packages/google-auth-oauthlib/testing/constraints-3.6.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#
66
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
77
# Then this file should have foo==1.14.0
8-
google-auth==2.14.0
8+
google-auth==2.15.0
99
requests-oauthlib==0.7.0
1010
click==6.0.0

packages/google-auth-oauthlib/testing/constraints-3.7.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#
66
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
77
# Then this file should have foo==1.14.0
8-
google-auth==2.14.0
8+
google-auth==2.15.0
99
requests-oauthlib==0.7.0
1010
click==6.0.0

packages/google-auth-oauthlib/tests/unit/test_helpers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ def test_credentials_from_session(session):
9696
assert credentials._client_secret == CLIENT_SECRETS_INFO["web"]["client_secret"]
9797
assert credentials._token_uri == CLIENT_SECRETS_INFO["web"]["token_uri"]
9898
assert credentials.scopes == session.scope
99+
assert credentials.granted_scopes is None
100+
101+
102+
def test_credentials_from_session_granted_scopes(session):
103+
granted_scopes = ["scope1", "scope2"]
104+
session.token = {
105+
"access_token": mock.sentinel.access_token,
106+
"refresh_token": mock.sentinel.refresh_token,
107+
"id_token": mock.sentinel.id_token,
108+
"expires_at": 643969200.0,
109+
"scope": granted_scopes,
110+
}
111+
112+
credentials = helpers.credentials_from_session(session, CLIENT_SECRETS_INFO["web"])
113+
114+
assert isinstance(credentials, google.oauth2.credentials.Credentials)
115+
assert credentials.token == mock.sentinel.access_token
116+
assert credentials.expiry == datetime.datetime(1990, 5, 29, 8, 20, 0)
117+
assert credentials._refresh_token == mock.sentinel.refresh_token
118+
assert credentials.id_token == mock.sentinel.id_token
119+
assert credentials._client_id == CLIENT_SECRETS_INFO["web"]["client_id"]
120+
assert credentials._client_secret == CLIENT_SECRETS_INFO["web"]["client_secret"]
121+
assert credentials._token_uri == CLIENT_SECRETS_INFO["web"]["token_uri"]
122+
assert credentials.scopes == session.scope
123+
assert credentials.granted_scopes == granted_scopes
99124

100125

101126
def test_credentials_from_session_3pi(session):

0 commit comments

Comments
 (0)