【发布时间】:2023-04-09 10:05:02
【问题描述】:
我最近将我的应用程序作为 SP(服务提供商)集成到充当 IdP(身份提供商)的 LMS(学习管理系统)。
这个想法是,一旦用户点击我在 LMS 工具上发布的课程,他将立即使用 IdP 用户身份验证服务 (SSO) 重定向到我的应用程序中的课程网址。
它只是部分工作。 SSO 有效,但一旦用户通过身份验证,他就会被重定向到我的应用程序中的索引页面,而不是课程的 url。
我去我的代码检查通过 saml 消息登录是如何工作的。在omniauth_callback_controller.rb 的登录方法是:
def saml
student = Student.where(email: request.env["omniauth.auth"]['uid'].to_s).first
if student
sign_in_and_redirect student, event: :authentication
else
flash[:error] = t 'flash_msg.access_1'
redirect_to root_path
end
end
然后我去设计检查“sign_in_and_redirect”方法的工作原理,它说:
# Sign in a user and tries to redirect first to the stored location and
# then to the url specified by after_sign_in_path_for. It accepts the same
# parameters as the sign_in method.
代码是:
def sign_in_and_redirect(resource_or_scope, *args)
options = args.extract_options!
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
sign_in(scope, resource, options)
redirect_to after_sign_in_path_for(resource)
end
最后我得出的结论是,要了解发生了什么,我必须了解:
- devise 的 sign_in_and_redirect 方法如何存储位置?根据方法解释,它“..尝试首先重定向到存储的位置”。
- 存储位置从何而来?我想它来自 IdP(一个 GET 请求?)。
- 如何检查 IdP 是否正在发送要存储的位置?我的日志中没有看到任何 GET 请求。只是带有 SAML 消息的 POST 请求。
谁能帮我解决这些问题?非常感谢。
【问题讨论】:
标签: ruby-on-rails redirect devise omniauth