Revert one commit - auth_provider.py import issues

This commit is contained in:
Ayush Shah 2021-08-14 09:09:20 +05:30
parent 3e6655d59b
commit 88968c0166

View File

@ -13,14 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time
import uuid
from google import auth, oauth2
from google.oauth2 import service_account
from metadata.config.common import ConfigModel
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass
from okta import jwt as oktajwt
from dataclasses import dataclass, field
import google.auth
import google.auth.transport.requests
from google.oauth2 import service_account
import time
import uuid
from jose import jwt
from okta.client import Client as OktaClient
import asyncio
from okta.jwt import JWT
class MetadataServerConfig(ConfigModel):
@ -72,10 +80,10 @@ class GoogleAuthenticationProvider(AuthenticationProvider):
return cls(config)
def auth_token(self) -> str:
credentials = oauth2.service_account.IDTokenCredentials.from_service_account_file(
credentials = service_account.IDTokenCredentials.from_service_account_file(
self.config.secret_key,
target_audience=self.config.audience)
request = auth.transport.requests.Request()
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials.token
@ -89,15 +97,15 @@ class OktaAuthenticationProvider(AuthenticationProvider):
return cls(config)
def auth_token(self) -> str:
my_pem, my_jwk = oktajwt.JWT.get_PEM_JWK(self.config.private_key)
my_pem, my_jwk = JWT.get_PEM_JWK(self.config.private_key)
claims = {
'sub': self.config.client_id,
'iat': time.time(),
'exp': time.time() + oktajwt.JWT.ONE_HOUR,
'exp': time.time() + JWT.ONE_HOUR,
'iss': self.config.client_id,
'aud': self.config.org_url + oktajwt.JWT.OAUTH_ENDPOINT,
'aud': self.config.org_url + JWT.OAUTH_ENDPOINT,
'jti': uuid.uuid4(),
'email': self.config.email
}
token = jwt.encode(claims, my_jwk.to_dict(), oktajwt.JWT.HASH_ALGORITHM)
token = jwt.encode(claims, my_jwk.to_dict(), JWT.HASH_ALGORITHM)
return token