使用Meteor
,coffeescript
和iron-router
,我成功地获得来自SAML身份提供程序(IDP)的用户。如何登录服务器端获取的SSO用户到Meteor帐户包中?
如何使用这些用户信息来登录,在通过流星账户包的用户?
考虑以下的服务器端路线:
Router.route '/sso/saml2', where: 'server', name:'ssoSaml'
.get ->
@response.writeHead 302, 'Location': saml.getRequestUrl()
@response.end()
.post ->
{secret:{password, email}, profile, state} = saml.getProfile @request.body.SAMLResponse
user= Meteor.users.findOne {'profile.domainId': profile.domainId}
userId = if user? then user._id else Accounts.createUser {password, email, profile}
# I have the user id - How do I sign the user in?
@response.writeHead 302, 'Location': "#{state.location}"
@response.end()
的过程如下:
- 的GET路线将浏览器重定向到的IdP终点与适当生成
SAMLRequest
。 - 对IDP处理
SAMLRequest
,并返回一个SAMLResponse
到POST路径。 - 的
SAMLResponse
处理返回用户的secret
领域,公共profile
以及包含最初请求location
- 一个
state
对象的唯一,不变的profile.domainId
用于从流星user
收集检索用户 - 如果没有
user
存在一个新的创建。
在这个过程的最后我有用户的详细信息,我知道用户存在于Meteor.users
集合中。要完成我需要登录用户并重定向到最初请求的位置。
如何登入用户?
您提到POST路由应该在客户端上运行。你能告诉我如何在这里SAMLResponse数据?在服务器上你可以看到我通过'@ request.body.SAMLResponse'得到它,但我找不到客户端路由的等价物。谢谢。 – biofractal
请参阅上面的**编辑1 **获取更多详细信息。 – biofractal
我相信已取得进展 - 感谢您的努力。请参阅**编辑2 **获取最新版本。 – biofractal