我正在尝试开发资源服务器,根据我在网上可以阅读的内容,得出的结论是,最好将身份验证方和资源方分开。 现在,我具有用于以下端点的身份验证的服务器
·https:authserver /注册/*saves the email+hash(password) on a db*/
·https:authserver /登录/*creates a session en a db and returns a session id in the cookies {secure, httpOnly}*/
·https:authserver /注销/*deletes the session*/
·https:authserver /检查/*given a session id returns if the session is valid*/
(authserver管理一个数据库,将会话和用户凭据保存在该数据库中)
对于我拥有的资源服务器
·https:资源服务器/注册/*saves email+name+birdthday+etc*/
·https:resourceserver / getResource /*returns protected resources*/
(资源服务器管理一个数据库,将用户数据以及首选项和照片/产品/评论/等保存在该数据库中)
但是现在我不知道这是一个好主意。我认为工作流程应该是这样,但是我觉得它有些混乱
用户转到registration.html,填写表格,然后:
One call to https:authserver/register
with body:{emil, password}
One call to https:resourceserver/register
with body:{emil, date, favorite color}
在这里我看到一个问题,那就是我必须检查两个调用是否都成功,如果不成功,请撤消使另一个调用成功的原因(如果在同一服务器上拥有auth和资源,如果出现问题,我不要不必撤消任何操作
如果两个呼叫均成功,则用户转到login.html,然后:
One call to https:authserver/login
with body:{emil, password} and the user gets in a cookie the session id
然后,如果用户想获取自己的照片,则可以转到photos.html,然后:
One call to https:resourceserver/getResource and the resourceserver gets the cookie
One call from resourceserver to http:sauthserver/check to know if the user is authorized to access
但是,如果因为httpOnly为true无法被前端读取,则主机B如何获得主机A设置的cookie?
我首先使用Json Web令牌实现了这一目的,因为我将令牌存储在LocalStorage中,所以两台主机都可以使用它,但我知道JWT存储中存在安全问题。
我认为我不了解如何区分身份验证和资源,有人可以帮助我了解正确的工作流程吗?或有任何意见或建议?
预先感谢