-
Notifications
You must be signed in to change notification settings - Fork 37
auth: allow external accounts to login and restrict upload #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,8 +85,10 @@ def find_remote_by_client_id(client_id): | |
|
|
||
| def fetch_extra_data(resource): | ||
| """Return a dict with extra data retrieved from CERN OAuth.""" | ||
| person_id = resource.get("cern_person_id") | ||
| return dict(person_id=person_id, groups=resource["groups"]) | ||
| data = {"groups": resource.get("groups", [])} | ||
| if resource.get("cern_person_id"): | ||
| data["person_id"] = resource["cern_person_id"] | ||
| return data | ||
|
|
||
|
|
||
| def account_roles_and_extra_data(account, resource, refresh_timedelta=None): | ||
|
|
@@ -178,10 +180,19 @@ def _account_info(remote, resp): | |
| resp, | ||
| ) | ||
|
|
||
| email = resource["email"] | ||
| external_id = str(resource["cern_uid"]) | ||
| nice = resource["preferred_username"] | ||
| name = resource["name"] | ||
| email = resource.get("email") | ||
| if not email: | ||
| raise OAuthCERNRejectedAccountError("No email in userinfo", remote, resp) | ||
|
|
||
| external_id = resource.get("cern_uid") or resource.get("sub") | ||
| if not external_id: | ||
| raise OAuthCERNRejectedAccountError("No external_id in userinfo", remote, resp) | ||
| external_id = str(external_id) | ||
| raw_username = resource.get("preferred_username") or email | ||
| if "@" in raw_username: | ||
| raw_username = raw_username.replace("@", "_").replace(".", "_") | ||
| nice = raw_username | ||
| name = resource.get("name") or nice | ||
|
zubeydecivelek marked this conversation as resolved.
|
||
|
|
||
| return dict( | ||
| user=dict(email=email.lower(), profile=dict(username=nice, full_name=name)), | ||
|
|
@@ -231,7 +242,7 @@ def account_setup(remote, token, resp): | |
| resource = get_resource(remote, resp) | ||
|
|
||
| with db.session.begin_nested(): | ||
| external_id = resource.get("cern_uid") | ||
| external_id = resource.get("cern_uid") or resource.get("sub") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it's unique, See here |
||
|
|
||
| # Set CERN person ID in extra_data. | ||
| token.remote_account.extra_data = {"external_id": external_id} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,9 +41,12 @@ cds users create test@test.ch -a --password=123456 | |
| # Create an admin user | ||
| cds users create admin@test.ch -a --password=123456 | ||
| cds roles create admin | ||
| cds roles create cern-user | ||
| cds roles add test@test.ch cern-user | ||
| cds roles add admin@test.ch admin | ||
| cds access allow deposit-admin-access role admin | ||
| cds access allow superuser-access role admin | ||
| cds access allow videos-upload-access role cern-user | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remember to apply this when deploying. You might want to already do it in all instances to be sure that you don't forget. |
||
|
|
||
| # Create a default files location | ||
| cds files location --default videos /tmp/files | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in which cases we have a
.and you replace it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have @ in
preferred_usernamewhich is email/gmail account, you have......@gmail.comand as username.also invalid. that's why I'm replacing but it can changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, we did not do that in CDS-RDM. We are using the
subfor the username, see here.