Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 1 | # Copyright 2016 Google Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import datetime |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 16 | import json |
| 17 | import os |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 18 | |
| 19 | import mock |
Thea Flowers | 118c048 | 2018-05-24 13:34:07 -0700 | [diff] [blame] | 20 | import pytest |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 21 | |
| 22 | from google.auth import _helpers |
Thea Flowers | 118c048 | 2018-05-24 13:34:07 -0700 | [diff] [blame] | 23 | from google.auth import exceptions |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 24 | from google.auth import transport |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 25 | from google.oauth2 import credentials |
| 26 | |
| 27 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 28 | DATA_DIR = os.path.join(os.path.dirname(__file__), "..", "data") |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 29 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 30 | AUTH_USER_JSON_FILE = os.path.join(DATA_DIR, "authorized_user.json") |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 31 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 32 | with open(AUTH_USER_JSON_FILE, "r") as fh: |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 33 | AUTH_USER_INFO = json.load(fh) |
| 34 | |
| 35 | |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 36 | class TestCredentials(object): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 37 | TOKEN_URI = "https://example.com/oauth2/token" |
| 38 | REFRESH_TOKEN = "refresh_token" |
| 39 | CLIENT_ID = "client_id" |
| 40 | CLIENT_SECRET = "client_secret" |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 41 | |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 42 | @classmethod |
| 43 | def make_credentials(cls): |
| 44 | return credentials.Credentials( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 45 | token=None, |
| 46 | refresh_token=cls.REFRESH_TOKEN, |
| 47 | token_uri=cls.TOKEN_URI, |
| 48 | client_id=cls.CLIENT_ID, |
| 49 | client_secret=cls.CLIENT_SECRET, |
| 50 | ) |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 51 | |
| 52 | def test_default_state(self): |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 53 | credentials = self.make_credentials() |
| 54 | assert not credentials.valid |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 55 | # Expiration hasn't been set yet |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 56 | assert not credentials.expired |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 57 | # Scopes aren't required for these credentials |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 58 | assert not credentials.requires_scopes |
Jon Wayne Parrott | 2d0549a | 2017-03-01 09:27:16 -0800 | [diff] [blame] | 59 | # Test properties |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 60 | assert credentials.refresh_token == self.REFRESH_TOKEN |
| 61 | assert credentials.token_uri == self.TOKEN_URI |
| 62 | assert credentials.client_id == self.CLIENT_ID |
| 63 | assert credentials.client_secret == self.CLIENT_SECRET |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 64 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 65 | @mock.patch("google.oauth2._client.refresh_grant", autospec=True) |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 66 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 67 | "google.auth._helpers.utcnow", |
| 68 | return_value=datetime.datetime.min + _helpers.CLOCK_SKEW, |
| 69 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 70 | def test_refresh_success(self, unused_utcnow, refresh_grant): |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 71 | token = "token" |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 72 | expiry = _helpers.utcnow() + datetime.timedelta(seconds=500) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 73 | grant_response = {"id_token": mock.sentinel.id_token} |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 74 | refresh_grant.return_value = ( |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 75 | # Access token |
| 76 | token, |
| 77 | # New refresh token |
| 78 | None, |
| 79 | # Expiry, |
| 80 | expiry, |
| 81 | # Extra data |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 82 | grant_response, |
| 83 | ) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 84 | |
| 85 | request = mock.create_autospec(transport.Request) |
| 86 | credentials = self.make_credentials() |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 87 | |
| 88 | # Refresh credentials |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 89 | credentials.refresh(request) |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 90 | |
| 91 | # Check jwt grant call. |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 92 | refresh_grant.assert_called_with( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 93 | request, |
| 94 | self.TOKEN_URI, |
| 95 | self.REFRESH_TOKEN, |
| 96 | self.CLIENT_ID, |
| 97 | self.CLIENT_SECRET, |
| 98 | None, |
| 99 | ) |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 100 | |
| 101 | # Check that the credentials have the token and expiry |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 102 | assert credentials.token == token |
| 103 | assert credentials.expiry == expiry |
| 104 | assert credentials.id_token == mock.sentinel.id_token |
Jon Wayne Parrott | 10ec7e9 | 2016-10-17 10:46:38 -0700 | [diff] [blame] | 105 | |
| 106 | # Check that the credentials are valid (have a token and are not |
| 107 | # expired) |
Jon Wayne Parrott | 78fec2c | 2017-06-30 10:25:08 -0700 | [diff] [blame] | 108 | assert credentials.valid |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 109 | |
Thea Flowers | 118c048 | 2018-05-24 13:34:07 -0700 | [diff] [blame] | 110 | def test_refresh_no_refresh_token(self): |
| 111 | request = mock.create_autospec(transport.Request) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 112 | credentials_ = credentials.Credentials(token=None, refresh_token=None) |
Thea Flowers | 118c048 | 2018-05-24 13:34:07 -0700 | [diff] [blame] | 113 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 114 | with pytest.raises(exceptions.RefreshError, match="necessary fields"): |
Thea Flowers | 118c048 | 2018-05-24 13:34:07 -0700 | [diff] [blame] | 115 | credentials_.refresh(request) |
| 116 | |
| 117 | request.assert_not_called() |
| 118 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 119 | @mock.patch("google.oauth2._client.refresh_grant", autospec=True) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 120 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 121 | "google.auth._helpers.utcnow", |
| 122 | return_value=datetime.datetime.min + _helpers.CLOCK_SKEW, |
| 123 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 124 | def test_credentials_with_scopes_requested_refresh_success( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 125 | self, unused_utcnow, refresh_grant |
| 126 | ): |
| 127 | scopes = ["email", "profile"] |
| 128 | token = "token" |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 129 | expiry = _helpers.utcnow() + datetime.timedelta(seconds=500) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 130 | grant_response = {"id_token": mock.sentinel.id_token} |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 131 | refresh_grant.return_value = ( |
| 132 | # Access token |
| 133 | token, |
| 134 | # New refresh token |
| 135 | None, |
| 136 | # Expiry, |
| 137 | expiry, |
| 138 | # Extra data |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 139 | grant_response, |
| 140 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 141 | |
| 142 | request = mock.create_autospec(transport.Request) |
| 143 | creds = credentials.Credentials( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 144 | token=None, |
| 145 | refresh_token=self.REFRESH_TOKEN, |
| 146 | token_uri=self.TOKEN_URI, |
| 147 | client_id=self.CLIENT_ID, |
| 148 | client_secret=self.CLIENT_SECRET, |
| 149 | scopes=scopes, |
| 150 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 151 | |
| 152 | # Refresh credentials |
| 153 | creds.refresh(request) |
| 154 | |
| 155 | # Check jwt grant call. |
| 156 | refresh_grant.assert_called_with( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 157 | request, |
| 158 | self.TOKEN_URI, |
| 159 | self.REFRESH_TOKEN, |
| 160 | self.CLIENT_ID, |
| 161 | self.CLIENT_SECRET, |
| 162 | scopes, |
| 163 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 164 | |
| 165 | # Check that the credentials have the token and expiry |
| 166 | assert creds.token == token |
| 167 | assert creds.expiry == expiry |
| 168 | assert creds.id_token == mock.sentinel.id_token |
| 169 | assert creds.has_scopes(scopes) |
| 170 | |
| 171 | # Check that the credentials are valid (have a token and are not |
| 172 | # expired.) |
| 173 | assert creds.valid |
| 174 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 175 | @mock.patch("google.oauth2._client.refresh_grant", autospec=True) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 176 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 177 | "google.auth._helpers.utcnow", |
| 178 | return_value=datetime.datetime.min + _helpers.CLOCK_SKEW, |
| 179 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 180 | def test_credentials_with_scopes_returned_refresh_success( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 181 | self, unused_utcnow, refresh_grant |
| 182 | ): |
| 183 | scopes = ["email", "profile"] |
| 184 | token = "token" |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 185 | expiry = _helpers.utcnow() + datetime.timedelta(seconds=500) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 186 | grant_response = { |
| 187 | "id_token": mock.sentinel.id_token, |
| 188 | "scopes": " ".join(scopes), |
| 189 | } |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 190 | refresh_grant.return_value = ( |
| 191 | # Access token |
| 192 | token, |
| 193 | # New refresh token |
| 194 | None, |
| 195 | # Expiry, |
| 196 | expiry, |
| 197 | # Extra data |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 198 | grant_response, |
| 199 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 200 | |
| 201 | request = mock.create_autospec(transport.Request) |
| 202 | creds = credentials.Credentials( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 203 | token=None, |
| 204 | refresh_token=self.REFRESH_TOKEN, |
| 205 | token_uri=self.TOKEN_URI, |
| 206 | client_id=self.CLIENT_ID, |
| 207 | client_secret=self.CLIENT_SECRET, |
| 208 | scopes=scopes, |
| 209 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 210 | |
| 211 | # Refresh credentials |
| 212 | creds.refresh(request) |
| 213 | |
| 214 | # Check jwt grant call. |
| 215 | refresh_grant.assert_called_with( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 216 | request, |
| 217 | self.TOKEN_URI, |
| 218 | self.REFRESH_TOKEN, |
| 219 | self.CLIENT_ID, |
| 220 | self.CLIENT_SECRET, |
| 221 | scopes, |
| 222 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 223 | |
| 224 | # Check that the credentials have the token and expiry |
| 225 | assert creds.token == token |
| 226 | assert creds.expiry == expiry |
| 227 | assert creds.id_token == mock.sentinel.id_token |
| 228 | assert creds.has_scopes(scopes) |
| 229 | |
| 230 | # Check that the credentials are valid (have a token and are not |
| 231 | # expired.) |
| 232 | assert creds.valid |
| 233 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 234 | @mock.patch("google.oauth2._client.refresh_grant", autospec=True) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 235 | @mock.patch( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 236 | "google.auth._helpers.utcnow", |
| 237 | return_value=datetime.datetime.min + _helpers.CLOCK_SKEW, |
| 238 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 239 | def test_credentials_with_scopes_refresh_failure_raises_refresh_error( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 240 | self, unused_utcnow, refresh_grant |
| 241 | ): |
| 242 | scopes = ["email", "profile"] |
| 243 | scopes_returned = ["email"] |
| 244 | token = "token" |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 245 | expiry = _helpers.utcnow() + datetime.timedelta(seconds=500) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 246 | grant_response = { |
| 247 | "id_token": mock.sentinel.id_token, |
| 248 | "scopes": " ".join(scopes_returned), |
| 249 | } |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 250 | refresh_grant.return_value = ( |
| 251 | # Access token |
| 252 | token, |
| 253 | # New refresh token |
| 254 | None, |
| 255 | # Expiry, |
| 256 | expiry, |
| 257 | # Extra data |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 258 | grant_response, |
| 259 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 260 | |
| 261 | request = mock.create_autospec(transport.Request) |
| 262 | creds = credentials.Credentials( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 263 | token=None, |
| 264 | refresh_token=self.REFRESH_TOKEN, |
| 265 | token_uri=self.TOKEN_URI, |
| 266 | client_id=self.CLIENT_ID, |
| 267 | client_secret=self.CLIENT_SECRET, |
| 268 | scopes=scopes, |
| 269 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 270 | |
| 271 | # Refresh credentials |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 272 | with pytest.raises( |
| 273 | exceptions.RefreshError, match="Not all requested scopes were granted" |
| 274 | ): |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 275 | creds.refresh(request) |
| 276 | |
| 277 | # Check jwt grant call. |
| 278 | refresh_grant.assert_called_with( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 279 | request, |
| 280 | self.TOKEN_URI, |
| 281 | self.REFRESH_TOKEN, |
| 282 | self.CLIENT_ID, |
| 283 | self.CLIENT_SECRET, |
| 284 | scopes, |
| 285 | ) |
Eugene W. Foley | 49a18c4 | 2019-05-22 13:50:38 -0400 | [diff] [blame] | 286 | |
| 287 | # Check that the credentials have the token and expiry |
| 288 | assert creds.token == token |
| 289 | assert creds.expiry == expiry |
| 290 | assert creds.id_token == mock.sentinel.id_token |
| 291 | assert creds.has_scopes(scopes) |
| 292 | |
| 293 | # Check that the credentials are valid (have a token and are not |
| 294 | # expired.) |
| 295 | assert creds.valid |
| 296 | |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 297 | def test_from_authorized_user_info(self): |
| 298 | info = AUTH_USER_INFO.copy() |
| 299 | |
| 300 | creds = credentials.Credentials.from_authorized_user_info(info) |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 301 | assert creds.client_secret == info["client_secret"] |
| 302 | assert creds.client_id == info["client_id"] |
| 303 | assert creds.refresh_token == info["refresh_token"] |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 304 | assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT |
| 305 | assert creds.scopes is None |
| 306 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 307 | scopes = ["email", "profile"] |
| 308 | creds = credentials.Credentials.from_authorized_user_info(info, scopes) |
| 309 | assert creds.client_secret == info["client_secret"] |
| 310 | assert creds.client_id == info["client_id"] |
| 311 | assert creds.refresh_token == info["refresh_token"] |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 312 | assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT |
| 313 | assert creds.scopes == scopes |
| 314 | |
| 315 | def test_from_authorized_user_file(self): |
| 316 | info = AUTH_USER_INFO.copy() |
| 317 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 318 | creds = credentials.Credentials.from_authorized_user_file(AUTH_USER_JSON_FILE) |
| 319 | assert creds.client_secret == info["client_secret"] |
| 320 | assert creds.client_id == info["client_id"] |
| 321 | assert creds.refresh_token == info["refresh_token"] |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 322 | assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT |
| 323 | assert creds.scopes is None |
| 324 | |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 325 | scopes = ["email", "profile"] |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 326 | creds = credentials.Credentials.from_authorized_user_file( |
Bu Sun Kim | 9eec091 | 2019-10-21 17:04:21 -0700 | [diff] [blame] | 327 | AUTH_USER_JSON_FILE, scopes |
| 328 | ) |
| 329 | assert creds.client_secret == info["client_secret"] |
| 330 | assert creds.client_id == info["client_id"] |
| 331 | assert creds.refresh_token == info["refresh_token"] |
Hiranya Jayathilaka | 23c88f7 | 2017-12-05 09:29:59 -0800 | [diff] [blame] | 332 | assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT |
| 333 | assert creds.scopes == scopes |