Skip to content

Commit

Permalink
multi tenant oauth object
Browse files Browse the repository at this point in the history
  • Loading branch information
ioigoume committed Oct 18, 2023
1 parent 9097fe7 commit 815a684
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/logger/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from app.utils import configParser
from logging.handlers import TimedRotatingFileHandler

FORMATTER = logging.Formatter("""%(asctime)s - %(name)s - %(levelname)s -
%(message)s""")
FORMATTER = logging.Formatter("""%(asctime)s - %(name)s - %(levelname)s - %(message)s""")
LOG_FILE = "{0}/{1}".format(configParser.getConfig('logging', 'config.global.py')['folder'],
configParser.getConfig('logging', 'config.global.py')['file'])
LEVEL = configParser.getConfig('logging', 'config.global.py')['level']
Expand Down
8 changes: 4 additions & 4 deletions app/routers/authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initializeAuthOb():
oauth = OAuth()

oauth.register(
'rciam',
g.tenant + '.' + g.environment + '.rciam',
client_id=oidc_config['client_id'],
client_secret=oidc_config['client_secret'],
server_metadata_url=oidc_config['issuer'] + "/.well-known/openid-configuration",
Expand All @@ -46,7 +46,7 @@ async def login_endpoint(
request: Request,
oauth_ob= Depends(initializeAuthOb),
server_config= Depends(getServerConfig)):
rciam = oauth_ob.create_client('rciam')
rciam = oauth_ob.create_client(g.tenant + '.' + g.environment + '.rciam')
redirect_uri = server_config['protocol'] + "://" + server_config['host'] + server_config['api_path'] + "/auth"
return await rciam.authorize_redirect(request, redirect_uri)

Expand All @@ -71,7 +71,7 @@ async def authorize_rciam(
response = RedirectResponse(url=urllib.parse.unquote(login_start_url))
response.delete_cookie("login_start")

rciam = oauth_ob.create_client('rciam')
rciam = oauth_ob.create_client(g.tenant + '.' + g.environment + '.rciam')
try:
token = await rciam.authorize_access_token(request)
except OAuthError as error:
Expand Down Expand Up @@ -148,7 +148,7 @@ async def logout(
oauth_ob= Depends(initializeAuthOb),
server_config=Depends(getServerConfig)
):
rciam = oauth_ob.create_client('rciam')
rciam = oauth_ob.create_client(g.tenant + '.' + g.environment + '.rciam')
metadata = await rciam.load_server_metadata()
# todo: Fix this after we complete the multitenacy
redirect_uri = server_config['protocol'] + "://" + server_config['client'] +"/metrics"
Expand Down
4 changes: 2 additions & 2 deletions app/utils/globalMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def __call__(self, request: Request, response: Response):
self.logger.debug("""{0}.{1}: Config File Name: {2}""".format(g.tenant, g.environment, config_file))

self.oauth.register(
'rciam',
g.tenant + '.' + g.environment + '.rciam',
client_id=oidc_config['client_id'],
client_secret=oidc_config['client_secret'],
server_metadata_url=oidc_config['issuer'] + "/.well-known/openid-configuration",
Expand All @@ -42,7 +42,7 @@ async def __call__(self, request: Request, response: Response):

# permissions calculation
access_token = request.headers.get('x-access-token')
rciam = self.oauth.create_client('rciam')
rciam = self.oauth.create_client(g.tenant + '.' + g.environment + '.rciam')
metadata = await rciam.load_server_metadata()

headers = {'Authorization': f'Bearer {access_token}'}
Expand Down

0 comments on commit 815a684

Please sign in to comment.