|
2 | 2 |
|
3 | 3 | from django.utils import timezone |
4 | 4 |
|
5 | | -from framework import bcrypt |
| 5 | +from framework import bcrypt, sentry |
6 | 6 | from framework.auth import signals |
7 | 7 | from framework.auth.core import Auth |
8 | 8 | from framework.auth.core import get_user, generate_verification_key |
9 | | -from framework.auth.exceptions import DuplicateEmailError |
| 9 | +from framework.auth.exceptions import DuplicateEmailError, MultipleSSOEmailError |
10 | 10 | from framework.auth.tasks import update_user_from_activity |
11 | 11 | from framework.auth.utils import LogLevel, print_cas_log |
12 | 12 | from framework.celery_tasks.handlers import enqueue_task |
@@ -154,11 +154,26 @@ def get_or_create_institutional_user(fullname, sso_email, sso_identity, primary_ |
154 | 154 | # CASE 5/5: If no user is found, create a confirmed user and return the user and sso identity. |
155 | 155 | # Note: Institution users are created as confirmed with a strong and random password. Users don't need the |
156 | 156 | # password since they sign in via SSO. They can reset their password to enable email/password login. |
157 | | - user = OSFUser.create_confirmed(sso_email, str(uuid.uuid4()), fullname) |
| 157 | + # user = OSFUser.create_confirmed(sso_email, str(uuid.uuid4()), fullname) |
| 158 | + user = OSFUser.create_confirmed(sso_email, 'abCD12#$', fullname) |
158 | 159 | user.add_system_tag(institution_source_tag(primary_institution._id)) |
159 | 160 | return user, True, None, None, sso_identity |
160 | 161 |
|
161 | 162 |
|
| 163 | +def deduplicate_sso_attributes(institution, sso_identity, attr_name, attr_value, delimiter=';', ignore_errors=True): |
| 164 | + if delimiter not in attr_value: |
| 165 | + return attr_value |
| 166 | + value_set = set(attr_value.split(delimiter)) |
| 167 | + if len(value_set) != 1: |
| 168 | + message = (f'Multiple values {attr_value} found for SSO attribute {attr_name}: ' |
| 169 | + f'[institution_id={institution._id}, sso_identity={sso_identity}]') |
| 170 | + if ignore_errors: |
| 171 | + sentry.log_message(message) |
| 172 | + return attr_value |
| 173 | + raise MultipleSSOEmailError(message) |
| 174 | + return value_set.pop() |
| 175 | + |
| 176 | + |
162 | 177 | def get_or_create_user(fullname, address, reset_password=True, is_spam=False): |
163 | 178 | """ |
164 | 179 | Get or create user by fullname and email address. |
|
0 commit comments