Skip to content

Commit

Permalink
feat: Introduce granted scopes to credentials (#257)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sai-sunder-s authored Dec 8, 2022
1 parent a3d7bd6 commit 51fef3b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
name: unittest
jobs:
unit:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
Expand Down
1 change: 1 addition & 0 deletions google_auth_oauthlib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def credentials_from_session(session, client_config=None):
client_id=client_config.get("client_id"),
client_secret=client_config.get("client_secret"),
scopes=session.scope,
granted_scopes=session.token.get("scope"),
)
credentials.expiry = datetime.datetime.utcfromtimestamp(session.token["expires_at"])
return credentials
3 changes: 2 additions & 1 deletion owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
)
s.move(templated_files, excludes=[
"docs/multiprocessing.rst",
"README.rst"
"README.rst",
".github/workflows/unittest.yml" #remove this exclusion when removing 3.6 from unit test
])

# Change black paths
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

TOOL_DEPENDENCIES = "click>=6.0.0"

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


with io.open("README.rst", "r") as fh:
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
# Then this file should have foo==1.14.0
google-auth==2.14.0
google-auth==2.15.0
requests-oauthlib==0.7.0
click==6.0.0
2 changes: 1 addition & 1 deletion testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
# Then this file should have foo==1.14.0
google-auth==2.14.0
google-auth==2.15.0
requests-oauthlib==0.7.0
click==6.0.0
25 changes: 25 additions & 0 deletions tests/unit/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ def test_credentials_from_session(session):
assert credentials._client_secret == CLIENT_SECRETS_INFO["web"]["client_secret"]
assert credentials._token_uri == CLIENT_SECRETS_INFO["web"]["token_uri"]
assert credentials.scopes == session.scope
assert credentials.granted_scopes is None


def test_credentials_from_session_granted_scopes(session):
granted_scopes = ["scope1", "scope2"]
session.token = {
"access_token": mock.sentinel.access_token,
"refresh_token": mock.sentinel.refresh_token,
"id_token": mock.sentinel.id_token,
"expires_at": 643969200.0,
"scope": granted_scopes,
}

credentials = helpers.credentials_from_session(session, CLIENT_SECRETS_INFO["web"])

assert isinstance(credentials, google.oauth2.credentials.Credentials)
assert credentials.token == mock.sentinel.access_token
assert credentials.expiry == datetime.datetime(1990, 5, 29, 8, 20, 0)
assert credentials._refresh_token == mock.sentinel.refresh_token
assert credentials.id_token == mock.sentinel.id_token
assert credentials._client_id == CLIENT_SECRETS_INFO["web"]["client_id"]
assert credentials._client_secret == CLIENT_SECRETS_INFO["web"]["client_secret"]
assert credentials._token_uri == CLIENT_SECRETS_INFO["web"]["token_uri"]
assert credentials.scopes == session.scope
assert credentials.granted_scopes == granted_scopes


def test_credentials_from_session_3pi(session):
Expand Down

0 comments on commit 51fef3b

Please sign in to comment.