Skip to content
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

Format response from Microsoft into expected auth.info format #24814

Merged
merged 1 commit into from Sep 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions dashboard/app/controllers/omniauth_callbacks_controller.rb
Expand Up @@ -65,6 +65,11 @@ def login
auth_hash = extract_powerschool_data(request.env["omniauth.auth"])
end

# Microsoft formats email and name differently, so update it to match expected structure
if provider == AuthenticationOption::MICROSOFT
auth_hash = extract_microsoft_data(request.env["omniauth.auth"])
end

@user = User.from_omniauth(auth_hash, auth_params)

# Set user-account locale only if no cookie is already set.
Expand Down Expand Up @@ -134,6 +139,16 @@ def extract_powerschool_data(auth)
auth
end

def extract_microsoft_data(auth)
auth_info = auth.info.merge(OmniAuth::AuthHash.new(
email: auth[:extra][:raw_info][:userPrincipalName],
ewjordan marked this conversation as resolved.
Show resolved Hide resolved
name: auth[:extra][:raw_info][:displayName]
)
)
auth.info = auth_info
auth
end

# Clever/Powerschool signins have unique requirements, and must be handled a bit outside the normal flow
def handle_untrusted_email_signin(user, provider)
force_takeover = user.teacher? && user.email.present? && user.email.end_with?('.oauthemailalreadytaken')
Expand Down