Skip to content

Commit

Permalink
Merge pull request #135 from sennetconsortium/libpitt/131-auth
Browse files Browse the repository at this point in the history
Libpitt/131 auth
  • Loading branch information
maxsibilla authored Sep 1, 2023
2 parents 29c4746 + 403e54d commit b897683
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/instance/app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ GLOBUS_ADMIN_FILE_USER_NAME = 'shirey'
GLOBUS_GENOMIC_DATA_FILE_GROUP_NAME = 'hubseq'
GLOBUS_CONSORTIUM_FILE_GROUP_NAME = 'hubmap'

#Sets the domain for the cookie set upon login to the portal. Use `localhost` for local development
COOKIE_DOMAIN = '.sennetconsortium.org'

#Entity-api
ENTITY_WEBSERVICE_URL = 'http://entity-api:8080'

Expand Down
14 changes: 11 additions & 3 deletions src/routes/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import Blueprint, redirect, request, session, current_app, Response
from flask import Blueprint, redirect, request, session, current_app, Response, make_response
from globus_sdk import AccessTokenAuthorizer, AuthClient, ConfidentialAppAuthClient
import json
import logging
import base64

from hubmap_commons.hm_auth import AuthHelper

Expand Down Expand Up @@ -102,8 +103,15 @@ def _login(redirect_uri, key = 'tokens'):
session[key] = token_response.by_resource_server

logger.info(f"Logged in User: {user_info['name']}")
# Finally redirect back to the client
return redirect(redirect_uri + '?info=' + str(json_str))

# encode this to avoid the \\" type strings when reading cookies from the client
b = base64.b64encode(bytes(json_str, 'utf-8')) # bytes
base64_json_str = b.decode('utf-8') # convert bytes to string

# create a response for the user
response = make_response(redirect(redirect_uri))
response.set_cookie('info', base64_json_str, expires=2**31 - 1, domain=current_app.config['COOKIE_DOMAIN'])
return response


def _logout(redirect_uri, app_name, key='tokens'):
Expand Down

0 comments on commit b897683

Please sign in to comment.