Skip to content

Commit

Permalink
add passport test
Browse files Browse the repository at this point in the history
  • Loading branch information
BinamB committed Aug 17, 2021
1 parent e31d29d commit 9496c0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions fence/resources/openid/ras_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,17 @@ def update_user_visas(self, user, pkey_cache, db_session=current_session):
current_db_session = db_session.object_session(visa)
current_db_session.add(visa)
db_session.commit()

def get_passport(self, user, db_session=current_session):
# get refresh_token from db
token_endpoint = self.get_value_from_discovery_doc("token_endpoint", "")
userinfo_endpoint = self.get_value_from_discovery_doc(
"userinfo_endpoint", ""
)
token = self.get_access_token(user, token_endpoint, db_session)
userinfo = self.get_userinfo(token, userinfo_endpoint)
encoded_visas = userinfo.get("ga4gh_passport_v1", [])

return encoded_visas


7 changes: 6 additions & 1 deletion fence/resources/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from fence.errors import NotFound, Unauthorized, UserError, InternalError
from fence.jwt.utils import get_jwt_header
from fence.models import query_for_user

from fence.resources.openid

logger = get_logger(__name__)

Expand Down Expand Up @@ -158,6 +158,11 @@ def get_user_info(current_session, username):
encoded_visas = [row.ga4gh_visa for row in user.ga4gh_visas_v1]
info["ga4gh_passport_v1"] = encoded_visas

client = flask.current_app.ras_client
passport = client.get_passport(user, current_session)

info["passport_v1"] = passport

return info


Expand Down

0 comments on commit 9496c0a

Please sign in to comment.