Skip to content

Commit

Permalink
Set cookie from python end - #131
Browse files Browse the repository at this point in the history
  • Loading branch information
libpitt committed Aug 28, 2023
1 parent 793840f commit cef3bbe
Showing 1 changed file with 11 additions and 3 deletions.
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
from flask import Blueprint, redirect, request, session, current_app, 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 @@ -94,8 +95,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)
return response


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

0 comments on commit cef3bbe

Please sign in to comment.