Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #352 from CSCfi/CSCMETAX-61-more-info-on-secure-page
Browse files Browse the repository at this point in the history
CSCMETAX-61: [ADD] Information to /secure about linked accounts, and …
  • Loading branch information
junsk1 authored Sep 28, 2018
2 parents 3e30e35 + ac1cc50 commit e7ddb80
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/metax_api/templates/secure/auth_success.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,30 @@ <h2>Where have I arrived?</h2>
<p>
This page gives you an authentication token that you can use to interact directly with Metax API. For more information, visit Metax documentation about <a href="/docs/end_users.html">End User Access</a>.
</p>
<p>
If you are going to interact with IDA file metadata, or publish datasets with IDA files, this is a good opportunity to link your CSC-account to your Fairdata-account. You can do that <a href="https://fd-perun.csc.fi/fed/ic/">here</a>. Once your accounts have been linked, it takes about an hour for your project information to become available for Metax.
</p>

<h3>You are logged in as:</h3>
<p>{{ email }}</p>

{% if linked_accounts %}
<h3>Linked accounts</h3>
<p>The following accounts have been linked with your Fairdata identity:</p>
<ul>
{% for acc in linked_accounts %}
<li>{{ acc }}</li>
{% endfor %}
</ul>
{% endif %}

{% if csc_account_linked %}
<p>
Your CSC-account is linked to your Fairdata identity, so you should be able to access your IDA projects using Metax, and other services. If you linked the account only a short while ago, it takes about an hour for your project information to become available for Metax.
</p>
{% else %}
<p>
Your Fairdata identity has not been linked with a CSC-account. If you are going to interact with IDA file metadata, or publish datasets with IDA files, this is a good opportunity to link your CSC-account to your Fairdata-account. You can do that <a href="https://fd-perun.csc.fi/fed/ic/">here</a>. Once your accounts have been linked, it takes about an hour for your project information to become available for Metax.
</p>
{% endif %}

<h3>Your token (id_token) is:</h3>
<p>{{ token_string }}</p>

Expand Down
14 changes: 14 additions & 0 deletions src/metax_api/views/secure/secure_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ def get(self, request, **kwargs):
token_payload = json.loads(request.META['HTTP_OIDC_ID_TOKEN_PAYLOAD'])
_logger.debug(token_payload)

linked_accounts = self._get_linked_accounts(token_payload)

for acc in linked_accounts:
if acc.endswith('@cscuserid'):
csc_account_linked = True
break
else:
csc_account_linked = False

context = {
'email': token_payload['email'],
'linked_accounts': linked_accounts,
'csc_account_linked': csc_account_linked,
'token_string': request.META['HTTP_OIDC_ID_TOKEN'],
'token_valid_until': datetime.fromtimestamp(token_payload['exp']).strftime('%Y-%m-%d %H:%M:%S'),
}

# note: django automatically searches templates from root directory templates/
return render(request, 'secure/auth_success.html', context=context)

def _get_linked_accounts(self, token_payload):
return [ acc for acc in token_payload.get('linkedIds', []) if not acc.endswith('@fairdataid') ]

0 comments on commit e7ddb80

Please sign in to comment.